Created
May 5, 2013 14:59
-
-
Save malfortuna/5521046 to your computer and use it in GitHub Desktop.
A bot used to tweet one Ludum Dare game per hour, over on Twitter at @LudumLegacy
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
import json, pprint, subprocess, urllib, urllib2, re, sys | |
import json as simplejson | |
import urllib2 | |
import xml.sax.saxutils | |
from getpass import getpass | |
from urllib import urlencode | |
import time, getopt | |
#sys.path = [ #Load of stupid path amendments for Dreamhost ] | |
import tinyurl, twitter, tweepy | |
####### | |
#BEGINS | |
####### | |
json_data=open('ludumdata.json').read() | |
data = json.loads(json_data) | |
baseurl = data['base_url'] + "?action=preview&uid=" | |
f = open('lastgametweeted.txt', 'r') | |
lastgame = f.readline() | |
thisgame = data['games'][0]['title'] | |
i = 0 | |
while(lastgame != thisgame): | |
i = i+1 | |
thisgame = (data['games'][i]['title']) | |
i = i+1 | |
thegame = data['games'][i] | |
charsremain = 140 | |
auth = tweepy.OAuthHandler("SECRET", "SECRET") | |
auth.set_access_token("SECRET", "SECRET") | |
api = tweepy.API(auth) | |
gametitle = thegame['title'] | |
gameurl = (tinyurl.create_one((baseurl+thegame['uid']))) | |
charsremain = charsremain - len(gameurl) | |
if(len(gametitle) + len(gameurl) + 8 > 140): | |
tweet = gametitle[:charsremain-3] | |
api.update_status(tweet+" - "+gameurl+" #ld48") | |
else: | |
charsremain = charsremain - len(gametitle) - 3 | |
gamedesc = thegame['description'][:(charsremain-10)] | |
print(gametitle+' - '+gamedesc+'... '+gameurl+' #ld48') | |
api.update_status(gametitle+' - '+gamedesc+'... '+gameurl+' #ld48'); | |
f.close() | |
f = open('lastgametweeted.txt', 'w') | |
f.write(gametitle) | |
f.close() | |
gameshoturl = "http://www.ludumdare.com/compo/wp-content/compo2/thumb/"+thegame['shots'][0]['thumb'] | |
print(gameshoturl) | |
image = urllib.URLopener() | |
image.retrieve(gameshoturl,"profilepic.png") | |
api.update_profile_image("./profilepic.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment