database - Get data from webpages with Python -
looking data specific website python upload onto google app engine. idea create database data store information on server retrieve , display in web app.
google.appengine.ext import webapp google.appengine.ext.webapp.util import run_wsgi_app google.appengine.ext import db import os import datetime google.appengine.ext.webapp import template # class creates pokemon on server class pokemondata(db.model): number = db.integerproperty() pokemonname = db.stringproperty() description = db.stringproperty() newpoke = pokemondata(number="001",pokemonname="balbasuar",description="the grass pokemon") newpoke = pokemondata(number="002",pokemonname="ivysaur",description="the seed pokemon") newpoke = pokemondata(number="003",pokemonname="venasaur",description="another grass pokemon") newpoke.put() # class put new pokemon in server ? class applyhandler(webapp.requesthandler): def post(self): self.session = session() pnumber = self.request.get('number') pname = self.request.get('pokemonname') pdescription = self.request.get('description') newpoke = pokemondata(number=pnumber,pokemonname=pname,description=pdescription) newpoke.put() self.session['pokemon'] = pname dorender(self,"board.htm",{}) # construct google table data # display class jsoninterface(webapp.requesthandler): def get(self): que = db.query(pokemondata) listing = que.fetch(limit = 12) dorender(self,'http://pokedexapp.appspot.com/?user=cater54321@gmail.com#input', {'listing':listing}) application = webapp.wsgiapplication([('/(.*html)?', applyhandler), ('/json', jsoninterface)], debug=true) def main(): run_wsgi_app(application) if __name__ == "__main__": main()
when deploy app test getting server error. can tell me if step in right direction , needs amending?
the yaml file
application: pokedexapp version: 1 runtime: python api_version: 1
handlers: - url: /.* script: main.py
from google.appengine.ext import db google.appengine.ext import webapp google.appengine.ext.webapp import template # class creates pokemon on server class pokemondata(db.model): number = db.integerproperty() pokemonname = db.stringproperty() description = db.stringproperty() def post(self): self.session = session() pnumber = self.request.get('number') pname = self.request.get('pokemonname') pdescription = self.request.get('description') newpoke = pokemondata(number=pnumber,pokemonname=pname,description=pdescription) newpoke.put() self.session['pokemon'] = pname dorender(self,"board.htm",{}) page = """ <html manifest="my.manifest"> <head> <!-- js , css header links go here --> </head> <body> <!-- needed html markup --> <!-- if there place need embed values (e.g. user name), use %s in place, e.g. --> <h1>%s's app engine app</h> <!-- can string substitution each %s (in order) - see end… </body> </html> """ # class / put pokemon in server ? class applyhandler(webapp.requesthandler): def post(self): self.session = session() pnumber = self.request.get('number') pname = self.request.get('pokemonname') pdescription = self.request.get('description') newpoke = pokemondata(number=pnumber,pokemonname=pname,description=pdescription) newpoke.put() self.session['pokemon'] = pname dorender(self,"board.htm",{}) # construct google big ass table data # display def get(self): que = db.query(pokemondata) listing = que.fetch(limit = 12) dorender(self,'http://pokedexapp.appspot.com/?user=cater54321@gmail.com#input', {'listing':listing}) #self.response.out.write( page % "fred bloggs") # standard google app engine stuff - create wsgi application # framework , set routing between uris , handlers... application = webapp.wsgiapplication([('/', pokemondata), ('/json', jsoninterface)], debug=true) def addlist(): run_wsgi_app(application) if __name__ == "__addlist__": main() code here
Comments
Post a Comment