Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit dcb5b33e29bb352ae3d61e91e01b9397fb51ba32 Michael Daugherty committed Mar 12, 2010
@@ -0,0 +1,12 @@
+application: outdoorsbeijing
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /stylesheets
+ static_dir: stylesheets
+- url: /js
+ static_dir: js
+- url: /.*
+ script: main.py
@@ -0,0 +1,4 @@
+cron:
+- description: update status from twitter
+ url: /tasks/updateStatus
+ schedule: every 1 hours
@@ -0,0 +1,23 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
+
+- kind: PollutantStatus
+ properties:
+ - name: date
+ direction: desc
+ - name: type
+
+- kind: PollutantStatus
+ properties:
+ - name: type
+ - name: date
+ direction: desc
@@ -0,0 +1,4 @@
+function a()
+{
+ alert("hi");
+}
71 main.py
@@ -0,0 +1,71 @@
+import cgi, urllib, os, datetime
+import simplejson
+
+from google.appengine.ext.webapp import template
+from google.appengine.api import users
+from google.appengine.ext import webapp
+from google.appengine.ext import db
+from google.appengine.ext.webapp.util import run_wsgi_app
+
+import twitter
+
+class PollutantStatus(db.Model):
+ type = db.StringProperty(required=True)
+ date = db.DateTimeProperty(required=True)
+ description = db.StringProperty(required=True)
+ concentration = db.FloatProperty(required=True)
+ aqi = db.IntegerProperty(required=True)
+
+class MainPage(webapp.RequestHandler):
+ def get(self):
+ self.response.out.write("<html><body>")
+ self.response.out.write("<h1>Beijing Air Status</h1>")
+ self.response.out.write(self.getCurrentPollutantHTML("PM2.5"))
+ self.response.out.write(self.getCurrentPollutantHTML("Ozone"))
+ self.response.out.write("</body></html>");
+
+ def getCurrentPollutantHTML(self, pollutant):
+ pm2Query = PollutantStatus.all()
+ pm2Query.order("-date")
+ pm2Query.filter("type = ", pollutant)
+ pm2Status = pm2Query.get()
+
+ htmlReturnValue = "<h2>"+pollutant+"</h2><div><em>"+pm2Status.description+"</em></div>"
+ htmlReturnValue += "<div>Concentration: <span>"+str(pm2Status.concentration)+"</span></div>"
+ htmlReturnValue += "<div>AQI: <span>"+str(pm2Status.aqi)+"</span></div>"
+
+ return htmlReturnValue
+
+class UpdateStatusFromTwitter(webapp.RequestHandler):
+ def get(self):
+ status = twitter.getStatus()
+ # Example status: "03-05-2010; 13:00; PM2.5; 17.0; 55; Moderate // Ozone; 43.3; 36; Good"
+ statusArray = status.split(";")
+ statusArray.insert(5, statusArray[5].split("//")[0])
+ statusArray[6] = statusArray[6].split("//")[1]
+ statusArray = map((lambda str: str.strip()),statusArray)
+ year = int(statusArray[0].split("-")[2])
+ day = int(statusArray[0].split("-")[1])
+ month = int(statusArray[0].split("-")[0])
+ hour = int(statusArray[1][0:2])
+ updateDateTime = datetime.datetime(year, month, day, hour)
+ for i in range(2, len(statusArray), 4):
+ newPollutantStatus = PollutantStatus(
+ type = statusArray[i],
+ date = updateDateTime,
+ description = statusArray[i+3],
+ concentration = float(statusArray[i+1]),
+ aqi = int(statusArray[i+2]))
+ newPollutantStatus.put()
+ self.response.out.write("Updated")
+
+application = webapp.WSGIApplication(
+ [('/', MainPage),
+ ('/tasks/updateStatus', UpdateStatusFromTwitter)],
+ debug=True)
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == "__main__":
+ main()
Oops, something went wrong.

0 comments on commit dcb5b33

Please sign in to comment.