Created
March 30, 2010 19:46
-
-
Save dvydra/349510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cgi | |
| from BeautifulSoup import BeautifulSoup | |
| import urllib | |
| import mechanize | |
| from string import strip | |
| from google.appengine.api import users | |
| from google.appengine.ext import webapp | |
| from google.appengine.ext.webapp.util import run_wsgi_app | |
| from google.appengine.ext import db | |
| class ShippingInfo(db.Model): | |
| id = db.IntegerProperty() | |
| url = db.StringProperty() | |
| emailAddress = db.EmailProperty() | |
| createDate = db.DateTimeProperty(auto_now_add=True) | |
| class MainPage(webapp.RequestHandler): | |
| def get(self): | |
| self.response.out.write(""" | |
| <html><body> | |
| <form action="/save" method="post"> | |
| <div>url: <input name="url" type="text"/></div> | |
| <div>email: <input name="emailAddress" type="text"/></div> | |
| <div><input type="submit" value="Sign Guestbook"></div> | |
| </form> | |
| </body></html> | |
| """) | |
| class AddShippingInfo(webapp.RequestHandler): | |
| def post(self): | |
| shippingInfo = ShippingInfo() | |
| shippingInfo.url = self.request.get('url') | |
| shippingInfo.emailAddress = self.request.get('emailAddress') | |
| shippingInfo.put() | |
| shippingInfo.id = shippingInfo.key().id() | |
| shippingInfo.put() | |
| self.response.out.write(shippingInfo.id) | |
| class ViewShippingStatus(webapp.RequestHandler): | |
| def get(self): | |
| id = self.request.get('id') | |
| shippingInfo = ShippingInfo.gql("where id="+id)[0] | |
| self.response.out.write(self.showInfo(shippingInfo)) | |
| def showInfo(self, shippingInfo): | |
| html = """ | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width,user-scalable=no" /> | |
| <title>has %s's stuff shipped?</title> | |
| <style> | |
| h1 { | |
| font-size: 80px; | |
| font-weight: bold; | |
| color: #FFFF00; | |
| text-align: center; | |
| } | |
| </style> | |
| </head> | |
| <body bgcolor="%s"> | |
| <br/><br/><br/> | |
| <h1>%s</h1> | |
| </body> | |
| </html> | |
| """ | |
| #br = mechanize.Browser() | |
| #br.set_handle_robots(0) | |
| #self.response.out.write(shippingInfo.url+"|||"+shippingInfo.emailAddress) | |
| f = urllib.urlopen("http://store.apple.com/go/vieworder/W87168345/[email protected]/AOSA10000063608") | |
| body = f.read() | |
| soup = BeautifulSoup(body) | |
| try: | |
| status = strip(soup.findAll('div', {'class':'orderInfo'})[0].findAll('div', {'class':'headerTextwhite'})[0].string) | |
| except: | |
| status = 'page has changed' | |
| if status != 'Not yet shipped': | |
| color = "lightgreen" | |
| else: | |
| status = "no" | |
| color = "red" | |
| return html % (shippingInfo.emailAddress, color, status) | |
| application = webapp.WSGIApplication( | |
| [('/', MainPage), | |
| ('/save', AddShippingInfo), | |
| ('/view', ViewShippingStatus)], | |
| debug=True) | |
| def main(): | |
| run_wsgi_app(application) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment