-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.py
37 lines (27 loc) · 1.28 KB
/
twitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import tweepy
from time import sleep
import os
#from secrets import *
#config variables from Heroku
consumer_key = os.environ.get('consumer_key')
consumer_secret = os.environ.get('consumer_secret')
access_token = os.environ.get('access_token')
access_token_secret = os.environ.get('access_token_secret')
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search,
#geocode='39.8,-95.583068847656,2500km',
q='place:96683cc9126741d1 #journojobs OR #journalismjobs OR #mediajobs OR #journojob OR #journalismjobs OR #publicmediajobs OR #pubjobs OR #radiojobs OR "hiring a journalist" OR "new journalism job posting" OR "hiring an environmental reporter" OR "hiring a science journalist" OR "new reporting internship" ').items():
try:
# Add \n escape character to print() to organize tweets
print('\nTweet by: @' + tweet.user.screen_name)
# Retweet tweets as they are found
tweet.retweet()
print('Retweeted the tweet')
#sleep limits the tweeting to occur every __ seconds - let's try 6 hours between tweets
sleep(21600)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break