Skip to content

Instantly share code, notes, and snippets.

@daeken
Created August 31, 2012 18:15
Show Gist options
  • Save daeken/3556819 to your computer and use it in GitHub Desktop.
Save daeken/3556819 to your computer and use it in GitHub Desktop.
import requests, re, time
from twitter import *
from pprint import pprint
tldrs = [x.strip() for x in file('tldrs.txt', 'r').readlines()]
fp = file('tldrs.txt', 'a')
# secret shit here.
t = Twitter(auth=OAuth(oauth_token, oauth_token_secret, consumer_key, consumer_secret))
tldr = re.compile('^tl[;:/\-]dr:?\s(.*)$', re.I | re.M)
def post(tweet):
if tweet in tldrs:
print 'Repeat:', tweet
return
print 'Posting:', tweet
t.statuses.update(status=tweet)
print >>fp, tweet
tldrs.append(tweet)
def comment(data, url):
for entry in tldr.findall(data):
post('tl;dr: ' + entry + ' - ' + url)
while True:
print 'Running'
try:
feed = requests.get('http://reddit.com/r/sex.json').json
for elem in feed['data']['children']:
try:
elem = elem['data']
baselink = 'http://reddit.com' + elem['permalink']
if elem['is_self']:
comment(elem['selftext'], baselink)
try:
cfeed = requests.get(baselink + '.json').json
for celem in cfeed[1]['data']['children']:
try:
celem = celem['data']
comment(celem['body'], baselink + celem['id'])
except:
pass
except:
pass
except:
continue
except:
continue
print 'Sleeping'
time.sleep(30*60) # 30 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment