With about 15% of Twitter being composed of bots, I wanted to try my hand at it.
Twitter Profile: NineBit
I hold no liability for what you do with this script or what happens to you by using this script. Abusing this script can get you banned from Twitter, so make sure to read up on proper usage of the Twitter API.
- Make a Twitter bot using Tweepy (An easy-to-use Python library for accessing the Twitter API).
- Use PRAW (The Python Reddit API Wrapper) Python package.
- Deploy your Reddit Bot on Heroku - A platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud
In this repo, I have made a twitter bot that cross post content between reddit's subreddit and Twitter.
Download all the required packages
pip install tweepy
pip install pygsheets
pip install praw
pip install wget
Next, we need to link our Twitter account to our Python script. Go to Twitter Developers and sign in with your account. Create a Twitter application and generate Consumer Key, Consumer Secret, Access Token, and Access Token Secret.
Obtain OAuth2 credentials from Google Developers Console for google spreadsheet api and drive api and save the file as google-credentials.json
Obtain credentials from Reddit preferences for reddit api.
- To post tweets.
- To like all tweets posted.
Pygsheets:A simple, intuitive python library to access google spreadsheets through the Google Sheets API v4.
- To maintain records of all tweets posted.
- To avoid duplicate tweets.
- To manage hastag list.
- To manage subreddit list.
- To search for submission within subreddits.
- To download images from reddit.
To host python script on HerokuHeroku you need to do a few things.
- Define a
requirements.txt
file in the root of your project that lists your dependencies. This is what Heroku will use to 'detect' you're using a Python app. - Add to Procfile:
worker: python main.py
- Save all your credentials in Config Vars (environment variables).
- To run the app correctly you need to save the content of your google credentials file in a variable named
GOOGLE_CREDENTIALS
and then create another environment variable with key=GOOGLE_APPLICATION_CREDENTIALS
and value =google-credentials.json
. - Then create a buildpack. Instructions Here
- Column A contains list of subreddits.
- Column B contains list of hashtag that goes with the tweet.
- Column C contains list of ids of post posted.
A | B | C |
---|---|---|
itookapicture | #MondayMood | hb1jdk |
spaceporn | #TuesdayThoughts | gm3ski |
wallpaper | #WednesdayWisdom | gt2p2u |
iWallpaper | #ThursdayThoughts | hbdpjv |
EarthPorn | #FridayFeeling | hbht7o |
telephotolandscapes | #SaturdayThoughts | har8qo |
BackgroundArt | #LazySunday | hb710q |
Concatenate post id at last to access the post on reddit and get more details. LINK
- Example : https://www.reddit.com/by_id/t3_hb1jdk
- To implement ML so that bot posts original content.
- To get meaningful insights on how people post throughout year.
This bot will continue to post until Heroku removes its free tier or I run out of Dyno hours.