Python 标记未显示在Google应用程序引擎中的Google地图上
我已经用Python创建了一个Google App Engine项目,它在我的本地主机上运行,但是当我将它上传到geo-event-maps.appspot.com上时,标记没有显示出来。 我有一个cron,可以运行来访问/放置。 我没有日志错误 我的数据存储是空的! 正在上载txt文件,其中包括:Python 标记未显示在Google应用程序引擎中的Google地图上,python,google-app-engine,google-maps,cron,google-maps-markers,Python,Google App Engine,Google Maps,Cron,Google Maps Markers,我已经用Python创建了一个Google App Engine项目,它在我的本地主机上运行,但是当我将它上传到geo-event-maps.appspot.com上时,标记没有显示出来。 我有一个cron,可以运行来访问/放置。 我没有日志错误 我的数据存储是空的! 正在上载txt文件,其中包括: file_path = os.path.dirname(__file__) path = os.path.join(file_path, 'storing', 'txtFiles')
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
有没有办法检查文件是否已上传
我完全不知所措。以前有人有过这些问题吗
下面是我的main.py:
'''
Created on Mar 30, 2011
@author: kimmasterson
'''
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext import db
from placemaker import placemaker
import logging
import wsgiref.handlers
import os, glob
from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.ext.webapp import template
class Story(db.Model):
id = db.StringProperty()
loc_name = db.StringProperty()
title = db.StringProperty()
long = db.FloatProperty()
lat = db.FloatProperty()
link = db.StringProperty()
date = db.StringProperty()
class MyStories(webapp.RequestHandler):
def get(self):
temp = db.Query(Story)
temp = temp.count()
story_set = Story.all()
template_values = {
'storyTemp': story_set
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class place(webapp.RequestHandler):
def get(self):
#path = '/storing/txtFiles'
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
try:
for infile in glob.glob(os.path.join(path, '*.txt')):
#print infile
f = open(infile, 'r')
data = f.read()
newfile = infile.replace('.txt', '')
newfile = newfile.replace('/storing/txtFiles/', '')
#print newfile
storyname = 'http://www.independent.ie/national-news/' + newfile
#print storyname
#print newfile
#logging.info(data)
p = placemaker('HSnG9pPV34EUBcexz.tDYuSrZ8Hnp.LowswI7TxreF8sXrdpVyVIKB4uPGXBYOA9VjjF1Ca42ipd_KhdJsKYjI5cXRo0eJM-')
print p.find_places(data)
for place in p.places:
splitted = place.name.split()
for word in splitted:
temp = db.Query(Story)
temp = temp.filter("link = ", storyname)
results = temp.fetch(limit=1)
if len(results) > 0:
break
elif 'IE' in word:
print temp
print 'success'
print 'name of the file is:' + newfile
story = Story(name=newfile, long=place.centroid.longitude, lat=place.centroid.latitude, link=storyname, loc_name=place.name, title=newfile).put()
#logging.info(type(place.centroid.latitude))
except:
print 'error'
def main():
application = webapp.WSGIApplication([('/', MyStories), ('/place', place)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
这是我的克朗。亚姆
cron:
- description: running place
url: /place
schedule: every day 11:05
App.yaml如下所示:
application: geo-event-maps
version: 2
runtime: python
api_version: 1
handlers:
- url: .*
script: main.py
builtins:
- datastore_admin: on
首先确保您正在使用相对路径访问文件
接下来,确保您没有在
应用程序中将文件标记为静态文件。yaml
因为静态文件不会上载到与您的应用程序相同的位置(它们被发送到Google前端服务器可以更直接地为其服务的某个位置)。您需要确保您的文件与您的应用程序代码一起上载,不能将它们标记为静态文件,否则代码将无法访问它们。使用--verbose
标志运行appcfg.py,并确保它们已上载
第二个问题,在place
类中,您将路径定义为path='/storing/txtFiles'
。这是错误的。您的路径可能更像:
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
另外,我建议您不要使用print
,而是使用self.response.out.write(stuff\u to\u write)
您可能还想了解如何使用密钥名称。通过在嵌套的for循环中运行batch db.get而不是db.Query,您可以使代码更加高效。使用并尽量减少RPC的数量。使用dev_appserver在本地是否可以做到这一点?你确定你的
infle在glob.glob中吗(…
block正在运行?可能您的文件并不是您希望它们在生产中出现的位置。我认为您应该缩小问题的范围并更新您的帖子。这就是我想知道如何发现我的文件是否被添加到服务器上的原因。它在本地主机上工作,地图在我的appspot上移动,但没有标记,因为atastore为空。您可能应该使用logging.debug(stuff\u to\u write)
,而不是在响应中返回在通过cron/taskqueue调用时不可见的内容。@Chris Yup,使用logging.debug()可能会更好。所有这些打印调用看起来都像是临时调试工具,用于直接调用url进行测试。我将main.py改为读入每个HTML文件,并向数据存储添加所需的位,只是查询数据存储,而不是尝试加载文件。非常感谢您的帮助:-)部署应用程序时,它显示“克隆919个应用程序文件。克隆100个文件。克隆200个文件。克隆300个文件。克隆400个文件。克隆500个文件。克隆600个文件。克隆700个文件。克隆800个文件。克隆900个文件。”这是否意味着文件肯定会被上传到服务器上?问题不在于它们是否被上传(它们将被上传)关键是它们是上载到GAE静态文件服务器还是GAE应用程序服务器。python代码只能访问发送到应用程序服务器的内容,因此如果txt
文件位于app.yaml
中标记为static的目录中,您将无法打开()。