Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
handle error better
  • Loading branch information
hickford committed May 12, 2011
1 parent b6d925c commit 761a5e7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lol.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
from BeautifulSoup import BeautifulSoup
import json
import urllib2
import urlparse
import os.path
Expand All @@ -11,15 +12,13 @@
homemade_url = "http://www.b3ta.com/links/popular/?i=1" # b3tan's own
#url = homemade_url

#from twitter import Twitter, NoAuth, OAuth, read_token_file
#from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
import twitter
import twitter.cmdline

oauth = twitter.OAuth(*twitter.read_token_file(os.path.expanduser('~/.twitter_oauth')) + (twitter.cmdline.CONSUMER_KEY, twitter.cmdline.CONSUMER_SECRET))
bird = twitter.Twitter(domain='api.twitter.com',auth=oauth, api_version='1')

for url in [links_url,homemade_url]:
for url in [homemade_url,links_url]:

page = urllib2.urlopen(url)
soup = BeautifulSoup(page)
Expand All @@ -37,7 +36,9 @@

if post.find(attrs={'class':'imadethis'}):
link = sburl

if url == links_url:
continue

bcreds= open(os.path.expanduser('~/.bitly_creds')).readlines()
blogin = bcreds[0].strip()
bapikey = bcreds[1].strip()
Expand All @@ -52,5 +53,14 @@

try:
bird.statuses.update(status=tweet)
except twitter.api.TwitterHTTPError, E:
pass
break
except twitter.api.TwitterHTTPError as E:
# print E
reason = json.loads(E.e.fp.read())['error']
print reason
if "duplicate" in reason:
break
else:
E.e.fp.write(reason)
raise twitter.api.TwitterHTTPError, E

0 comments on commit 761a5e7

Please sign in to comment.