Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some duplicate status detection and prevention - keep our data…

… clean!
  • Loading branch information...
commit f2545a01fbba47be1306d77d1ee18d567a157ce8 1 parent dcb5b33
@mpdaugherty authored
Showing with 12 additions and 5 deletions.
  1. +10 −3 main.py
  2. +2 −2 twitter.py
View
13 main.py
@@ -1,4 +1,4 @@
-import cgi, urllib, os, datetime
+import cgi, urllib, os, datetime, logging
import simplejson
from google.appengine.ext.webapp import template
@@ -56,8 +56,15 @@ def get(self):
description = statusArray[i+3],
concentration = float(statusArray[i+1]),
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(
[('/', MainPage),
View
4 twitter.py
@@ -2,7 +2,7 @@
import simplejson
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.
-# return "03-05-2010; 13:00; PM2.5; 88.0; 55; Moderate // Ozone; 43.3; 36; Good"
@mpdaugherty Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return "03-05-2010; 13:00; PM2.5; 88.0; 55; Moderate // Ozone; 43.3; 36; Good"
@mpdaugherty

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

Please sign in to comment.
Something went wrong with that request. Please try again.