Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a simple Twitter bot with Python #14

Closed
ykdojo opened this issue Oct 24, 2018 · 17 comments
Closed

Make a simple Twitter bot with Python #14

ykdojo opened this issue Oct 24, 2018 · 17 comments
Assignees

Comments

@ykdojo
Copy link
Owner

ykdojo commented Oct 24, 2018

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
Copy link

ghost commented Oct 24, 2018

What account should this bot control?

@ykdojo
Copy link
Owner Author

ykdojo commented Oct 24, 2018

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

@sameerchoubey
Copy link

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

@ykdojo
Copy link
Owner Author

ykdojo commented Oct 24, 2018

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

@ghost
Copy link

ghost commented Oct 24, 2018

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
Copy link
Owner Author

ykdojo commented Oct 24, 2018

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
Copy link

ghost commented Oct 24, 2018

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
Copy link
Owner Author

ykdojo commented Oct 25, 2018 via email

@ykdojo ykdojo changed the title Make a simple Twitter bot Make a simple Twitter bot with Python Nov 3, 2018
@ykdojo
Copy link
Owner Author

ykdojo commented Nov 3, 2018

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

@ykdojo ykdojo self-assigned this Nov 3, 2018
@ykdojo
Copy link
Owner Author

ykdojo commented Nov 3, 2018

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
Copy link
Owner Author

ykdojo commented Nov 4, 2018

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
Copy link
Owner Author

ykdojo commented Nov 5, 2018

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

@ykdojo
Copy link
Owner Author

ykdojo commented Nov 5, 2018

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
Copy link
Owner Author

ykdojo commented Nov 6, 2018

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

@ykdojo
Copy link
Owner Author

ykdojo commented Nov 6, 2018

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: tweepy/tweepy#1063

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

@ykdojo
Copy link
Owner Author

ykdojo commented Nov 8, 2018

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

@ykdojo
Copy link
Owner Author

ykdojo commented Nov 25, 2018

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

@ykdojo ykdojo closed this as completed Nov 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants