希望通过Python从特定网站获取数据,以便上传到Google App Engine。我们的想法是创建一个数据库数据来存储服务器上的信息,以便在Web应用程序中检索和显示。
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os
import datetime
from google.appengine.ext.webapp import template
# A class which creates all the pokemon on the 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()
# A class to put new pokemon in to the 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 a google table for this data
# to 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()
当我部署应用程序进行测试时,我收到服务器错误。谁能告诉我这是否是朝着正确方向迈出的一步以及需要修改的内容?
yaml文件目前是
申请:pokedexapp 版本:1 runtime:python api_version:1
处理程序: - 网址:/。* 脚本:main.py
答案 0 :(得分:0)
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
# A class which creates all the pokemon on the 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>
<!-- All the js and css header links go here -->
</head>
<body>
<!-- all the needed HTML markup -->
<!-- if there is a place you would need to embed values (e.g. a user name), just use %s in its place, e.g. -->
<h1>%s's App Engine App</h>
<!-- you can now do a string substitution for the each %s (in order) - see end…
</body>
</html>
"""
# A class to get / put pokemon in to the 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 a google big ass table for this data
# to 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")
# This is standard Google App Engine stuff - create a WSGI application
# framework and set up the routing between URIs and Handlers...
application = webapp.WSGIApplication([('/', Pokemondata),
('/json', JSONInterface)], debug=True)
def Addlist():
run_wsgi_app(application)
if __name__ == "__Addlist__":
main()
code here
答案 1 :(得分:0)
from google.appengine.ext import db
# A class which creates all the pokemon on the server
class Pokemondata(db.Model):
pokemonname = db.StringProperty()
newpoke = Pokemondata(pokemonname="Balbasuar")
newpoke.put()
class JSONInterface(webapp.RequestHandler):
def post(self):
pkmname = self.request.get('pokemonname')
callback = self.request.get('callback')
# This line makes the Message object...
pkmname = Pokemondata(pokemonname=pkmname)
# This one pushes it to the database (a Big-Table)...
pkmname.put()
self.response.out.write(getJSONMessages(callback))
def get(self):
callback = self.request.get('callback')
self.response.out.write(getJSONMessages(callback))
答案 2 :(得分:0)
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os
import datetime
from google.appengine.ext.webapp import template
# A class which creates all the pokemon on the server
class Pokemondata(db.Model):
def get(self):
pokemonname = db.StringProperty()
newpoke = Pokemondata(pokemonname="Balbasuar")
newpoke.put()
class JSONInterface(webapp.RequestHandler):
def post(self):
pkmname = self.request.get('pokemonname')
callback = self.request.get('callback')
# This line makes the Message object...
pkmname = Pokemondata(pokemonname=pkmname)
# This one pushes it to the database (a Big-Table)...
pkmname.put()
self.response.out.write(getJSONMessages(callback))
def get(self):
callback = self.request.get('callback')
self.response.out.write(getJSONMessages(callback))