Skip to content

Commit

Permalink
Adding some duplicate status detection and prevention - keep our data…
Browse files Browse the repository at this point in the history
… clean!
  • Loading branch information
mpdaugherty committed Mar 12, 2010
1 parent dcb5b33 commit f2545a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions main.py
@@ -1,4 +1,4 @@
import cgi, urllib, os, datetime import cgi, urllib, os, datetime, logging
import simplejson import simplejson


from google.appengine.ext.webapp import template from google.appengine.ext.webapp import template
Expand Down Expand Up @@ -56,8 +56,15 @@ def get(self):
description = statusArray[i+3], description = statusArray[i+3],
concentration = float(statusArray[i+1]), concentration = float(statusArray[i+1]),
aqi = int(statusArray[i+2])) aqi = int(statusArray[i+2]))
newPollutantStatus.put()
self.response.out.write("Updated") # Ensure that we aren't accidentally adding a duplicate status to
# the database
if PollutantStatus.gql("WHERE type = :1 AND date = :2", newPollutantStatus.type, newPollutantStatus.date).count() < 1:
newPollutantStatus.put()
else:
self.response.out.write("Duplicate status detected<br />")
logging.info("Duplicate status detected: "+newPollutantStatus.type+" "+str(newPollutantStatus.date));
self.response.out.write("Updated with "+status)


application = webapp.WSGIApplication( application = webapp.WSGIApplication(
[('/', MainPage), [('/', MainPage),
Expand Down
4 changes: 2 additions & 2 deletions twitter.py
Expand Up @@ -2,7 +2,7 @@
import simplejson import simplejson


def getStatus(): def getStatus():
return simplejson.load(urllib.urlopen("http://api.twitter.com/users/show/15527964.json"))['status']['text'] # return simplejson.load(urllib.urlopen("http://api.twitter.com/users/show/15527964.json"))['status']['text']


# The following line is for testing on my localhost, which is in Beijing and therefore Twitter is blocked. # The following line is for testing on my localhost, which is in Beijing and therefore Twitter is blocked.
# return "03-05-2010; 13:00; PM2.5; 88.0; 55; Moderate // Ozone; 43.3; 36; Good" return "03-05-2010; 13:00; PM2.5; 88.0; 55; Moderate // Ozone; 43.3; 36; Good"

This comment has been minimized.

Copy link
@mpdaugherty

mpdaugherty Mar 12, 2010

Author Owner

Commenting out the twitter API usage was a mistake - I was testing on localhost.

0 comments on commit f2545a0

Please sign in to comment.