Permalink
Browse files

Adding files, duh

  • Loading branch information...
1 parent 3aed5f7 commit 7423431e6db57ca9a015bdb0d659a2c03009ed9e @DFectuoso DFectuoso committed Aug 3, 2010
Showing with 45 additions and 0 deletions.
  1. +27 −0 dojo_name_api.py
  2. +18 −0 notify_io.py
View
@@ -0,0 +1,27 @@
+from google.appengine.api import urlfetch, memcache
+from google.appengine.api.labs import taskqueue
+
+# Hacker Dojo Domain API helper with caching
+def dojo_name(path, cache_ttl=3600):
+ base_url = 'http://domain.hackerdojo.com'
+ resp = memcache.get(path)
+ if not resp:
+ resp = urlfetch.fetch(base_url + path, deadline=10)
+ try:
+ resp = simplejson.loads(resp.content)
+ except Exception, e:
+ resp = []
+ cache_ttl = 10
+ memcache.set(path, resp, cache_ttl)
+ return resp
+
+# Return the name of a user from the memcache. If it was not set we set it and queue a query to the domain api
+def fullname(username):
+ fullname = memcache.get('/users/%s:fullname' % username)
+ if not fullname:
+ taskqueue.add(url='/worker/user', params={'username': username})
+ memcache.set('/users/%s:fullname' % username, username, 10)
+ return username
+ else:
+ return fullname
+
View
@@ -0,0 +1,18 @@
+from google.appengine.api import urlfetch
+import urllib, hashlib, keys
+
+# This notify method was taken from commitify @ http://github.com/whatcould/commitify/blob/master/main.py =D
+def notify(email, text, title, link=None):
+ params = {'text':text,'title':title}
+ if link:
+ params['link'] = link
+ count = 0
+ while True:
+ try:
+ return urlfetch.fetch('http://api.notify.io/v1/notify/%s?api_key=%s' % (hashlib.md5(email).hexdigest(), keys.api_key), method='POST', payload=urllib.urlencode(params))
+ except urlfetch.DownloadError:
+ count += 1
+ logging.debug('DownloadError on fetch: %s, %s' % (email, title))
+ if count == 3:
+ raise
+

0 comments on commit 7423431

Please sign in to comment.