yasoob / Reddit-Twitter-bot

This bot copies posts from /r/Python from Reddit and posts them to Twitter while keeping every safety measure in check.
9 stars 5 forks source link

2016 update for this bot #1

Closed zakagan closed 8 years ago

zakagan commented 8 years ago

Hi Yasoob!

I learned a ton of Python from reading your blog post but I noticed there were some issues as well. So, I've made this fix. I also have my own expanded version of this reddit bot here (created before I learned about pull requests).

Main changes:

  1. Google now requires an API key to access its shortener. This version adds that authentication, so that google shortened urls can be used. However, twitter will still use t.co's shortener regardless. Ultimately it is recommended to default to Twitter's url shortener via setting the google api key variable to "" (a blank string).
  2. The previous method for collecting posts stored them in a dict, and then iterated through that dict. Since dicts are implemented via hash tables, this resulted in posts being sent to twitter out of order to their current reddit ranking. I have corrected this by saving items from reddit in lists.
  3. You can now specify what hashtags you would like include at the top of the script. The program tracks words remaining and accommodates for whatever you decide to use. So long as you don't go past a character limit of 114. All links/media are allocated 24, and 2 are used for spaces.
  4. I added some small error checking features, and corrected an issue where the script would be unable to convert certain unicode characters to ascii (this was achieved by encoding to unicode).

I tried to retain the pythonic nature of your original design, while adding some additional functionality taken from my version of this project. I saw that some commenters on your blog post wanted an updated version. Maybe this could bit?

Thank you so much for creating this project and the blog in the first place!

Best, Zach

yasoob commented 8 years ago

Hey @zakagan! Thank you very much for your contribution :smile: That blog-post was written when I, myself was new to Python. I am glad that you learned a bit from it. :)

Keep rocking and contributing to Open Source and if you ever need my help I am just an email away.

yasoob commented 8 years ago

Would you like to make a PR for the README file as well?

zakagan commented 8 years ago

Sorry it took so long! I was backed up with other projects. But I wanted to finish the write-up and tie a bow on this script.

Thanks again for merging!