Permalink
Browse files

refactoring, added some helper scripts, and saving update times

  • Loading branch information...
1 parent 04ad798 commit 06056863f16022db9f3da94de56d238021b4ef30 @larryng committed May 10, 2012
Showing with 44 additions and 28 deletions.
  1. +1 −1 Procfile
  2. 0 iama/__init__.py
  3. +13 −0 iama/envvars.py
  4. +10 −26 { → iama}/go.py
  5. +19 −0 iama/utils.py
  6. +1 −1 requirements.txt
View
@@ -1 +1 @@
-go: python go.py
+go: python iama/go.py
View
No changes.
View
@@ -0,0 +1,13 @@
+# -*- coding: utf8 -*-
+
+import os
+import sys
+import urlparse
+
+USER_AGENT = os.environ['USER_AGENT']
+USERNAME = os.environ['REDDIT_USERNAME']
+PASSWORD = os.environ['REDDIT_PASSWORD']
+MONGO_URI = os.environ['MONGOLAB_URI']
+DB_NAME = urlparse.urlparse(MONGO_URI).path.strip('/')
+MIN_COMMENTS = int(os.environ.get('IAMA_MIN_COMMENTS', 200))
+WAIT_TIME = float(os.environ.get('IAMA_WAIT_TIME', 60.0))
View
@@ -1,21 +1,15 @@
-#!/usr/bin/python
# -*- coding: utf8 -*-
-import os
import sys
import time
+import datetime
import narwal
import pymongo
-import urlparse
+
+from utils import get_db, log, quotify
+from envvars import USERNAME, PASSWORD, MIN_COMMENTS, USER_AGENT, WAIT_TIME
-USER_AGENT = os.environ['USER_AGENT']
-USERNAME = os.environ['REDDIT_USERNAME']
-PASSWORD = os.environ['REDDIT_PASSWORD']
-MONGO_URI = os.environ['MONGOLAB_URI']
-DB_NAME = urlparse.urlparse(MONGO_URI).path.strip('/')
-MIN_COMMENTS = int(os.environ.get('IAMA_MIN_COMMENTS', 200))
-WAIT_TIME = float(os.environ.get('IAMA_WAIT_TIME', 60.0))
MAX_COMMENT_LENGTH = 10000
BASE_URL = u'http://www.reddit.com/'
@@ -46,20 +40,6 @@
)
-def get_db():
- connection = pymongo.Connection(MONGO_URI)
- return connection[DB_NAME]
-
-
-def log(s):
- print s.encode('utf8') # heroku can't log unicode
-
-
-def quotify(s):
- """reddit markdown quotes a string"""
- return u'> {}'.format(s.replace('\n', '\n> '))
-
-
def get_qalst(host, first_comments):
"""returns list of (question, answer) comment pairs
@@ -87,7 +67,8 @@ def helper(comments, parent=None):
def format_header(host):
"""formats header for our bot's first comment"""
return HEADER_FORMAT.format(
- last_updated=time.strftime(TIME_FORMAT, time.localtime()),
+ last_updated=datetime.datetime.strftime(datetime.datetime.now(),
+ TIME_FORMAT),
host=host
)
@@ -222,7 +203,10 @@ def post_pages(iama, pages, db=None):
# save to db
new_comp = {'link': iama.permalink,
- 'pages': new_pages}
+ 'pages': new_pages,
+ 'updated': datetime.datetime.now()} # yes, this will be slightly
+ # off, but who cares?
+
db.comps.update(query,
{'$set': new_comp},
upsert=True)
View
@@ -0,0 +1,19 @@
+# -*- coding: utf8 -*-
+
+import pymongo
+
+from envvars import MONGO_URI, DB_NAME
+
+
+def get_db():
+ connection = pymongo.Connection(MONGO_URI)
+ return connection[DB_NAME]
+
+
+def log(s):
+ print s.encode('utf8') # heroku can't log unicode
+
+
+def quotify(s):
+ """reddit markdown quotes a string"""
+ return u'> {}'.format(s.replace('\n', '\n> '))
View
@@ -1,7 +1,7 @@
certifi==0.0.8
chardet==1.0.1
distribute==0.6.24
-narwal==0.2.6a
+narwal==0.3.0b
pymongo==2.1.1
requests==0.11.2
wsgiref==0.1.2

0 comments on commit 0605686

Please sign in to comment.