-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet_wx_data.py
96 lines (96 loc) · 3.01 KB
/
tweet_wx_data.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Python 3
import tweepy, datetime
from sys import platform as _platform
#
# Define the cities considered
#
cities = ['SAC','SF','PDX','SV']
#
# Open the txt file previously created and create python List of tweets by cycling through the txt file
#
if _platform == "linux" or _platform == "linux2":
f = open('/home/dougdroplet2/projects/BikeWxX/BikeWxX/data/forecast.txt','r')
elif _platform == "darwin":
f = open('data/forecast.txt','r')
elif _platform == "win32":
print('if on win32, create a dir and continue')
#
tweettextlist = []
for item in f:
tweettextlist.append(item)
f.close
print(tweettextlist[0])
print()
#
# Cycle through the cities, get the keys, make the tweet, send the tweet
#
dict={}
#
# If it is before noon, send the ridein
# If it is after noon, send the ridehome
# Below assumes the server is on local time
now = datetime.datetime.now()
i = 0
#
for city in cities:
if _platform == "linux" or _platform == "linux2":
e = open('/home/dougdroplet2/projects/BikeWxX/bikewxxkeys/'+city+'keys','r')
elif _platform == "darwin":
e = open('../bikewxxkeys/'+city+'keys','r')
elif _platform == "win32":
print('create dir and continue')
dict = eval(e.read())
auth = tweepy.OAuthHandler(dict['API_KEY'], dict['API_SECRET'])
auth.set_access_token(dict['ACCESS_TOKEN'], dict['ACCESS_TOKEN_SECRET'])
api = tweepy.API(auth)
#
if datetime.time(now.hour)<datetime.time(12,0):
ride='Morning ride in:'
tweetext = ride
if tweettextlist[i+1][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+1]
if tweettextlist[i+9][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+9]
if tweettextlist[i+17][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+17]
if tweettextlist[i+25][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+25]
if tweettextlist[i+2][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + 'Ride home: ' + tweettextlist[i+2]
else:
ride='Evening ride home: '
tweetext = ride
if tweettextlist[i+1][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+1]
if tweettextlist[i+10][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+10]
if tweettextlist[i+18][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+18]
if tweettextlist[i+26][:7] == 'No data':
tweetext = tweetext
else:
tweetext = tweetext + tweettextlist[i+26]
print("")
print(city)
print(tweetext)
api.update_status(tweetext)
print('tweets away!')
i += 2
e.close
#