Permalink
Browse files

add logging

  • Loading branch information...
1 parent 8203cac commit 3297943f98eb41c9b6084455432a032000878e74 @xiaoganghan committed Feb 12, 2014
Showing with 5 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +4 −4 twitter-bot/twitter-bot.py
View
@@ -5,6 +5,7 @@
*.db
local_settings.py
+log.txt
# Packages
*.egg
@@ -8,6 +8,7 @@
import sqlite3
from local_settings import TwitterKey, BitlyKey
+logging.basicConfig(filename='log.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
def run():
@@ -33,13 +34,12 @@ def run():
jsondata = json.loads(urllib2.urlopen(url).read())
- tweets = ''
if 'data' in jsondata and 'children' in jsondata['data']:
posts = jsondata['data']['children']
posts.reverse()
for ind, post in enumerate(posts):
entry = post['data']
- logging.debug(entry['permalink'] + ' ' +entry['url'])
+ # logging.debug(entry['permalink'] + ' ' +entry['url'])
postid = entry['id']
num_comments = entry['num_comments']
@@ -54,10 +54,10 @@ def run():
url = shortapi.shorten(entry['url'])
author = entry['author']
status = ' %s [%s by:%s comments:%d score:%d]' % (url, permalink, author, num_comments, score)
- status = title[:(140 - len(status))] + status
+ status = title[:(135 - len(status))] + status
status = status.encode('utf-8')
+
logging.debug(status)
- tweets += '<p>' + status + '</p>'
bot.update_status(status)
cur.execute("INSERT INTO tweet_table VALUES (?, ?, ?)", [None, postid, None])
conn.commit()

0 comments on commit 3297943

Please sign in to comment.