标记未在Google App Engine中显示在Google地图上

jen*_*001 5 python cron google-app-engine google-maps google-maps-markers

我在Python中创建了一个Google App Engine项目,它在我的localhost上运行但是当我将它上传到geo-event-maps.appspot.com时,标记没有显示.我有一个cron,它可以调用/放置.我没有日志错误我的数据存储空了!正在上传txt文件:

    file_path = os.path.dirname(__file__)
    path = os.path.join(file_path, 'storing', 'txtFiles')
Run Code Online (Sandbox Code Playgroud)

有没有办法检查文件是否已上传?!

我绝对亏损.以前有没有人遇到过这些问题?

下面是我的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()
Run Code Online (Sandbox Code Playgroud)

这是我的cron.yaml

    cron:
- description: running place
  url: /place
  schedule: every day 11:05
Run Code Online (Sandbox Code Playgroud)

App.yaml如下:

application: geo-event-maps
version: 2
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py
builtins:
- datastore_admin: on
Run Code Online (Sandbox Code Playgroud)

Rob*_*uin 2

您需要确保您的文件是与您的应用程序代码一起上传的,它们不能被标记为静态文件,否​​则您的代码将无法访问它们。使用该--verbose标志运行 appcfg.py 并确保它们已上传。

第二个问题,在您的place班级中您将路径定义为path = '/storing/txtFiles'。那是错的。你的路径可能更像是:

file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
Run Code Online (Sandbox Code Playgroud)

另外,我建议你不要使用print,而是使用self.response.out.write(stuff_to_write).

您可能还想了解如何使用 key_names。通过在嵌套 for 循环内运行批处理 db.get 而不是 db.Query,您将能够使代码更加高效。使用Appstats并尝试最小化 RPC 的数量。