Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created May 5, 2013 15:36
Show Gist options
  • Save thomwiggers/5521151 to your computer and use it in GitHub Desktop.
Save thomwiggers/5521151 to your computer and use it in GitHub Desktop.
import simplejson, urllib, urllib2, cookielib, time, math
def conn(link, parameters):
f = cookie.open(link, parameters)
data = f.read()
f.close()
return data
def get(link):
f = cookie.open(link)
data = f.read()
f.close()
return data
thread = '22240'
page = '9999'
cfile = 'cookie.lwp'
cj = cookielib.LWPCookieJar()
cj.load(cfile)
cookie = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
data = get('https://what.cd/')
auth = data.split('authkey=')[1].split('"')[0]
jsonget = get('https://what.cd/ajax.php?action=forum&type=viewthread&threadid=' + thread + '&page=' + page)
parse = simplejson.loads(jsonget)
author = parse['response']['posts'][-1]['author']['authorName']
resp = parse['response']['posts'][-1]['body']
ptime = time.strptime(parse['response']['posts'][-1]['addedTime'], "%Y-%m-%d %H:%M:%S")
timediff = (-time.mktime(ptime) + time.mktime(time.gmtime()))/60-60
msg = "Last post " + str(int(math.floor(timediff))) + ' minutes ago! For shame!'
print msg
if timediff > 120:
print "submitting"
conn('https://what.cd/forums.php', urllib.urlencode({'action' : 'reply', 'auth' : auth, 'body' : msg, 'thread' : thread}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment