Skip to content

Instantly share code, notes, and snippets.

@philipp-r
Created May 28, 2020 15:45
Show Gist options
  • Save philipp-r/ce970d24bcbefff2d82990c51de84782 to your computer and use it in GitHub Desktop.
Save philipp-r/ce970d24bcbefff2d82990c51de84782 to your computer and use it in GitHub Desktop.
Twitter bot with tweepy (reply to tweets by search criteria)
import tweepy
import datetime
auth = tweepy.OAuthHandler("xxxxx", "xxxxxx")
auth.set_access_token("xxxx", "xxxxxxxxxx")
api = tweepy.API(auth)
#list of specific strings we want to check for in Tweets
t = [
'illegal die house of parliament',
'illegal die houses of parliament',
'illegal die westminster',
'forbidden die house of parliament',
'forbidden die westminster',
'verboten sterben westminster',
'verboten sterben house of parliament',
'verboten sterben houses of parliament' ]
for query in t:
twts = api.search(q=query)
for s in twts:
sn = s.user.screen_name
m = "@%s House of Commons authorities and Law Commission were not able to trace any law that forbids dying in Westminster Palace. State funerals are not mandatory if you die there. http://www.lawcom.gov.uk/app/uploads/2015/03/Legal_Oddities.pdf" % (sn)
print s.id
print s.created_at
dCreated = s.created_at
dToday = datetime.datetime.today()
delta = dCreated - dToday
if delta.days >= -1:
try:
s = api.update_status(status=m, in_reply_to_status_id=s.id)
print "post"
except tweepy.error.TweepError:
pass
else:
print "skip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment