Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created August 15, 2010 21:43
Show Gist options
  • Save alloy-d/525979 to your computer and use it in GitHub Desktop.
Save alloy-d/525979 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import sys
import time
import urllib
email = "adam@alloy-d.net"
password = "Haha, like I'd show you!"
def get_fix(start=0, num=50):
"""Returns an array of posts."""
url = "http://dianeisadork.tumblr.com/api/read/json"
params = urllib.urlencode({
'start': start,
'num': num,
})
r = urllib.urlopen(url+"?"+params)
if r.getcode() != 200:
print "Unable to get posts. :-("
return []
# [22:-2] strips "var tumblr_api_read = " and ";"
json_obj = json.loads(r.read()[22:-2])
return json_obj['posts']
def do_the_obvious_thing(post_id, reblog_key):
"""Likes a post."""
params = urllib.urlencode({
'email': email,
'password': password,
'post-id': post_id,
'reblog-key': reblog_key,
})
r = urllib.urlopen('http://www.tumblr.com/api/like', params)
if r.getcode() != 200:
print "Unable to like http://dianeisadork.tumblr.com/post/{0} :-(".format(post_id)
def auto_like_the_awesome_stuff_diane_posts(start=0, num=50, prev=0):
"""
Likes the last `num` posts from `start` until the post with id
`prev` is encountered.
"""
most_recent = prev
posts = get_fix(start, num)
if len(posts) > 0:
most_recent = posts[0]['id']
for post in posts:
if post['id'] == prev:
break
else:
do_the_obvious_thing(post['id'], post['reblog-key'])
return most_recent
if __name__ == "__main__":
prev = 0
while True:
prev = auto_like_the_awesome_stuff_diane_posts(prev=prev)
time.sleep(60*60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment