forked from pimoroni/internet-of-seeds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internet-of-seeds-tweet.py
executable file
·32 lines (28 loc) · 1.17 KB
/
internet-of-seeds-tweet.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
import json
import tweepy
## Function to tweet sensor values and a timestamped image. Needs to be passed
## status (timestamp and sensor values pulled from data log) and the latest
## image filename.
def tweet_pic(status, latest, config_f='config.json'):
with open(config_f) as f:
config = json.load(f)
ckey = config['tweepy']['ckey']
csecret = config['tweepy']['csecret']
akey = config['tweepy']['akey']
asecret = config['tweepy']['asecret']
auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(akey, asecret)
api = tweepy.API(auth)
api.update_with_media(latest, status=status)
## Set the latest image filename, grab the last line from the data log.
tispic = '2_TiSImages/' # Folder for overlaid images
latest = tispic + 'latest_ts.jpg'
fn = 'InternetOfSeeeeds.log'
with open(fn) as f:
for l in f.readlines():
pass
## Format the sensor values nicely for tweeting, run the tweet_pic function.
sensor_vals = l.rstrip().split('\t')
status = '%s: Temp: %s C, Press: %s hPa, Light: %s lux, CCT: %sK, Disk Free: %s Mb' % (sensor_vals[0], sensor_vals[1], sensor_vals[2], sensor_vals[3], sensor_vals[7], sensor_vals[8])
#print status
tweet_pic(status, latest)