ykdojo / editdojo

(I'm no longer working on this - currently working on https://github.com/ykdojo/defaang)
https://www.csdojo.io/edit
MIT License
333 stars 98 forks source link

Make a simple Twitter bot with Python #14

Closed ykdojo closed 5 years ago

ykdojo commented 5 years ago

This is just so that we can learn how to use Twitter API.

Maybe something that says "hello, world back to you!" when it receives a Twitter mention that says "hello, world!"

ghost commented 5 years ago

What account should this bot control?

ykdojo commented 5 years ago

this one: https://twitter.com/editdojo

sameerchoubey commented 5 years ago

@ykdojo We can use the Tweepy library along with the Twitter API which we can get through Developer account.

ykdojo commented 5 years ago

Okay sounds good. I already got a developer account for @editdojo :)

ghost commented 5 years ago

To set up Tweepy we need the consumer key, consumer secret, a access token and a access token secret. Is publicly posting these keys and tokens from the editdojo account a security risk?

ykdojo commented 5 years ago

Yeah I think it's best to put those files in .gitignore.

Then, each of us can get a Twitter dev account separately and test it with our own Twitter account?

ghost commented 5 years ago

I was thinking the consumer information could be stored into a config.json file, and change the .gitignore to ignore it. This way we each only need to create the json file with the four required info. Or is there a better way to store this information

ykdojo commented 5 years ago

That sounds like a good method!

On Wed, Oct 24, 2018 at 5:41 PM Kyle McCullen notifications@github.com wrote:

I was thinking the consumer information could be stored into a config.json file, and change the .gitignore to ignore it. This way we each only need to create the json file with the four required info. Or is there a better way to store this information

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ykdojo/editdojo/issues/14#issuecomment-432838165, or mute the thread https://github.com/notifications/unsubscribe-auth/ABukw3ESCWv2QjIiGMDs0HoEd9NGkvxfks5uoN5ogaJpZM4X4ZPs .

ykdojo commented 5 years ago

I'm thinking of working on this one next. I'm probably going to make a video about this, too.

ykdojo commented 5 years ago

Find some references for this.

The official Tweepy documentation: https://tweepy.readthedocs.io/en/v3.6.0/index.html A freeCodeCamp article: https://medium.freecodecamp.org/creating-a-twitter-bot-in-python-with-tweepy-ac524157a607

I'll try following them and see if I can understand them first.

ykdojo commented 5 years ago

The freeCodeCamp article was kind of follow, but I found another article on this topic.

https://dev.to/emcain/how-to-set-up-a-twitter-bot-with-python-and-heroku-1n39

This looks more promising. Will take a look at it tomorrow morning, I think.

ykdojo commented 5 years ago

I'm thinking of putting the keys in a separate Python file and call it keys.py or something.

ykdojo commented 5 years ago

So for Twitter API, looks like we have these two choices:

  1. Filter realtime tweets: https://developer.twitter.com/en/docs/tweets/filter-realtime/overview
  2. Get Tweet timelines: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline.html
ykdojo commented 5 years ago

Ugh looks like Tweepy is not compatible with Python 3.7. Maybe I'll use Python 3.6 instead.

ykdojo commented 5 years ago

Turns out, downgrading Python is a huge pain.

So, I used this command instead to install a more recent version of tweepy:

pipenv install -e git+https://github.com/tweepy/tweepy.git@2efe385fc69385b57733f747ee62e6be12a1338b#egg=tweepy

I found a related command for this here: https://github.com/tweepy/tweepy/issues/1063

I also used this as a reference: https://realpython.com/pipenv-guide/#example-usage

ykdojo commented 5 years ago

K this is done. I'm planning to publish a video about it tomorrow. https://github.com/ykdojo/twitterbotsample

ykdojo commented 5 years ago

Just for a reference, here's the video: https://youtu.be/W0wWwglE1Vc