Skip to content

Commit

Permalink
Better @dojo handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dustball committed Aug 2, 2013
1 parent e655a07 commit 8ad0088
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cron.yaml
Expand Up @@ -7,5 +7,5 @@ cron:

- description: cache usersnames
url: /cron/fetchusers
schedule: every 1 hour
schedule: every 1 hours
timezone: America/Los_Angeles
22 changes: 16 additions & 6 deletions main.py
Expand Up @@ -207,6 +207,17 @@ def get(self):
email = self.request.get('email')
# time.sleep(2)
type = self.request.get('type')

if "@hackerdojo.com" in email:
usernames = memcache.get('usernames')
username = string.split(email,"@")[0]
if usernames and "[" in usernames and username not in usernames:
response = {"error": "Member not found", "nomember":"true"}
self.response.out.write(json.dumps(response))
for ch in (range(1,3)):
channel.send_message("CH"+str(ch),json.dumps({"email":email,"first":"","last":"","count":-1}))
return

if email and type:
signin = Signin.signin(email, type)
record = SigninRecord.signin(email, datetime.now())
Expand All @@ -218,18 +229,14 @@ def get(self):
response = {"signins":record.signins, "name":signin.name, "tos":tos}
else:
response = {"error": "need to specify email and type"}

current_event = Event.get_current_event()
if current_event and datetime.now()>current_event.from_time and datetime.now() < current_event.to_time:
urlfetch.fetch(url=current_event.webhook_url,
payload=self.request.query_string,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})

if "@hackerdojo.com" in email:
usernames = memcache.get('usernames')
username = string.split(email,"@")[0]
if usernames and "[" in usernames and username not in usernames:
response = {"error": "Member not found", "nomember":"true"}

self.response.out.write(json.dumps(response))

Expand Down Expand Up @@ -300,6 +307,9 @@ def post(self):
# Used by /log - the user facing log of people that have signed in last 12 hours
class LogHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url('/log'))
staff_db = db.GqlQuery("SELECT * FROM Signin WHERE created >= DATETIME(:earlier_this_morning) ORDER BY created desc LIMIT 500",
earlier_this_morning=(datetime.now(Pacific()).strftime("%Y-%m-%d 00:00:00")))
staff = []
Expand Down Expand Up @@ -582,7 +592,7 @@ def get(self):
resp = urlfetch.fetch('http://domain.hackerdojo.com/users', deadline=20)
if resp.status_code == 200:
memcache.set('usernames', resp.content, 3600*2)
self.response.out.write("200 OK - Usernames set")
self.response.out.write("<h1>200 OK - Usernames set</h1>")
else:
self.response.out.write("500 - Something broke")

Expand Down
1 change: 1 addition & 0 deletions templates/rtlog.html
Expand Up @@ -104,6 +104,7 @@
if (s.count==1) icon = "http://i.imgur.com/uQdPsaI.png";
if (s.count>15) icon = "http://i.imgur.com/eYAnC.jpg";
if (s.email.indexOf("@hackerdojo.com")>0) icon = "http://i.imgur.com/AM7rGV1.png";
if (s.count==-1) icon = "http://i.imgur.com/3frBOKO.png";
sendnote(s.count+": "+s.email,icon);

$(".template .email").html(s.email);
Expand Down

0 comments on commit 8ad0088

Please sign in to comment.