This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests, random, time, pytumblr | |
from PIL import Image | |
from StringIO import StringIO | |
import tweepy | |
# Twitter API details | |
auth = tweepy.OAuthHandler("blahblahblah", "blahblahblah") | |
auth.set_access_token('blahblahblah', 'blahblahblah') | |
# Authenticate via OAuth | |
tumblrClient = pytumblr.TumblrRestClient( | |
'blahblahblah', | |
'blahblahblah', | |
'blahblahblah', | |
'blahblahblah' | |
) | |
# Make the request | |
tumblrClient.info() | |
api = tweepy.API(auth) | |
# Okay, making two versions of this file. One for Katharine and one for Mary Lee. | |
# Katharine tweets 0,6,18 | |
# Katharine json http://www.ocearch.org/tracker/ajax/filter-sharks/?sharks[]=65&tracking-activity=+&gender=+&stage-of-life=+&location=0 | |
# Mary Lee tweets 3,9,21 | |
# Mary Lee json http://www.ocearch.org/tracker/ajax/filter-sharks/?sharks[]=41&tracking-activity=+&gender=+&stage-of-life=+&location=0 | |
# This is Mary Lee's Bot | |
# Get Data | |
r = requests.get('http://www.ocearch.org/tracker/ajax/filter-sharks/?sharks[]=41&tracking-activity=+&gender=+&stage-of-life=+&location=0').json() | |
latitude = r[0]['pings'][0]['latitude'] | |
longitude = r[0]['pings'][0]['longitude'] | |
datetime = r[0]['pings'][0]['datetime'] | |
name = r[0]['name'] | |
length = r[0]['length'] | |
weight = r[0]['weight'] | |
distance = r[0]['dist_total'] | |
latestPing = r[0]['latestPing'] | |
# Count the number of pings | |
item_dict = r | |
ping_count = len(item_dict[0]['pings']) | |
# Count lines in H.D.'s poems | |
with open('hd_poems.txt') as f: | |
poem_length = sum(1 for _ in f) | |
# Read three lines from H.D. Poems | |
line1 = random.randint(1,poem_length) | |
line2 = random.randint(1,poem_length) | |
line3 = random.randint(1,poem_length) | |
f = open('hd_poems.txt','r') | |
lines = f.readlines() | |
verse = lines[line1].capitalize() + lines[line2] + lines[line3].rstrip('\n,.?;:') + "." | |
# See if there's been a new ping | |
f = open('marylee_ping.txt','r') | |
datain = f.read() | |
f.close() | |
if str(datain) == str(latestPing): | |
random_ping = random.randint(0,ping_count-1) | |
latitude = r[0]['pings'][random_ping]['latitude'] | |
longitude = r[0]['pings'][random_ping]['longitude'] | |
datetime = r[0]['pings'][random_ping]['datetime'] | |
time_convert = time.strptime(datetime,'%d %B %Y %I:%M:%S %p') | |
short_time = time.strftime('%m/%d/%y',time_convert) | |
update = verse + "\n\n - M.L." + " (" + short_time + ")" | |
else: | |
old_latitude = r[0]['pings'][1]['latitude'] | |
old_longitude = r[0]['pings'][1]['longitude'] | |
verbs = ["appeared at ", "surfaced at ", "pinged satellites at ", "was detected at ", "rose to the surface, coordinates "] | |
pronouns = ["--I--", "--that is I--","--me!--"] | |
pronoun = random.choice(pronouns) | |
verb = random.choice(verbs) | |
update = datetime + ": " + name + pronoun + verb + latitude + ", " + longitude + "." | |
f = open('marylee_ping.txt','w') | |
f.write(str(latestPing)) | |
f.close() | |
# Dealing with the map | |
mapURL = "http://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&size=600x300&zoom=7&sensor=false&maptype=hybrid&markers=" + latitude + "," + longitude | |
m = requests.get(mapURL) | |
gmap = Image.open(StringIO(m.content)) | |
gmap.save('map.gif','gif') | |
print update | |
tumblrUpdate = update + "\n\nComposed at " + latitude + ", " + longitude | |
#api.update_with_media('map.gif',status=update) | |
tumblrClient.create_photo("maryleeandkatharine", state="published", tags=["sharks", "poetry", "marylee"], caption=tumblrUpdate, data="map.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment