Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tjukanovt
Created July 2, 2018 18:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tjukanovt/42403afc1ac3c1211e044405bf61572f to your computer and use it in GitHub Desktop.
Save tjukanovt/42403afc1ac3c1211e044405bf61572f to your computer and use it in GitHub Desktop.
A super simple Twitter bot application posting random csv content every 2 hours
import tweepy
import random
import pandas as pd
import time
#get your codes from https://apps.twitter.com/
consumer_key = 'your_code_here'
consumer_secret = 'your_code_here'
access_token = 'your_code_here'
access_token_secret = 'your_code_here'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#change this to match your file
df = pd.read_csv('your_csv_file.csv', encoding='latin-1', error_bad_lines=False, delimiter=';')
#in my csv file the data starts from column 7 and row index one.
#From there I read a random cell content and post that to Twitter
while True:
readCol = random.randrange(7,len(df.columns))
readRow = random.randrange (1,len(df.index))
tweet = str(df.iat[readRow, readCol])
if len(tweet) > 10 and len(tweet) < 280:
api.update_status(tweet)
time.sleep(10800)
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment