如何正确添加PyTZ到Google App Engine应用程序? [英] How to properly add PyTZ to a Google App Engine application?

查看:100
本文介绍了如何正确添加PyTZ到Google App Engine应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有点尴尬,但我没有找到关于这个话题的好资源。



我正在开发一个需要的Google App Engine应用程序精密的时区转换。由于我没有接近强加的配额,我已经选择与PyTZ一起去。但是,我一定在做错事。目前为止,我所做的是:


  1. 将PyTZ作为压缩包下载

  2. pytz
    目录复制到我的应用程序的根目录
    (它是一个兄弟的 webapp
    目录,其中 app.yaml 位于)。

然而,如果我尝试实例化时区,PyTZ似乎找不到任何东西。以下是GAE交互式控制台的示例会话:

  '欧洲/罗马')

输出如下:

 追溯(最近的最后一次呼叫):
文件/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/
exec(compiled_code,globals())
文件< string>,第3行,< string_>模块>
文件/Library/Python/2.5/site-packages/pytz-2009j-py2.5.egg/pytz/__init__.py,第157行,时区
UnknownTimeZoneError:'Europe / Rome'

我做错了什么?感谢您的帮助。



注意:如果我只是在本地使用python交互式shell,事情会按预期工作:

 >>>从pytz import datetime,timezone 
>>>> rome =时区('Europe / Rome')
>>> rome.localize(datetime.datetime.now())
datetime.datetime(2009,11,12,0,4,52,990114,tzinfo =< DstTzInfo'Europe / Rome'CET + 1:00: 00 STD>)

编辑:我需要澄清我不是使用压缩版本的PyTZ。我的项目中包含了整个 zoneinfo 目录:

  pc- morena:pytz lyudmilangelov $ cd zoneinfo / 
pc-morena:zoneinfo lyudmilangelov $ ls -l
total 448
drwxr-xr-x @ 55 lyudmilangelov staff 1870 Nov 10 12:48 Africa
drwxr-xr-x @ 135 lyudmilangelov工作人员4590 11月10日12:48美国
drwxr-xr-x @ 12 lyudmilangelov工作人员408 Nov 10 12:48南极洲
drwxr-xr-x @ 3 lyudmilangelov工作人员102 Nov 10 12:48 Arctic
drwxr-xr-x @ 93 lyudmilangelov staff 3162 Nov 10 12:48 Asia
...


解决方案

针对这个问题,从 gae-pytz 我创建了 pytz-appengine 。特别是pytz-appengine将所有时区信息放入 ndb 数据存储区。



单元测试pytz pass至少只要他们通过上游)。使用pytz-appengine的主要动机是使需要更新时区数据库变得微不足道。有一个构建脚本 build.py 自动执行此操作。



我欢迎任何反馈。 >

This is a little embarrassing, but I have not been able to find good resources on this topic.

I'm working on a Google App Engine application that requires sophisticated time zone conversions. Since I am nowhere near the imposed quotas, I have opted to go with PyTZ. However, I must be doing something wrong. What I've done so far is:

  1. Downloaded PyTZ as a tarball
  2. Installed it and copied the pytz directory into the root of my app (it is a sibling of the webapp directory, where app.yaml is located).

However, if I try to instantiate timezones, PyTZ can never seem to find any. Here is a sample session from GAE's interactive console:

from pytz import timezone

rome = timezone('Europe/Rome')

The output is the following:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/admin/__init__.py", line 210, in post
    exec(compiled_code, globals())
  File "<string>", line 3, in <module>
  File "/Library/Python/2.5/site-packages/pytz-2009j-py2.5.egg/pytz/__init__.py", line 157, in timezone
UnknownTimeZoneError: 'Europe/Rome'

What is it I am doing wrong? Thank you in advance for your help.

NOTE: If I just use the python interactive shell locally things work as expected:

>>> from pytz import datetime, timezone
>>> rome = timezone('Europe/Rome')
>>> rome.localize(datetime.datetime.now())
datetime.datetime(2009, 11, 12, 0, 4, 52, 990114, tzinfo=<DstTzInfo 'Europe/Rome' CET+1:00:00 STD>)

Edit: I need to clarify I'm not using a zipped version of PyTZ. I have included the whole zoneinfo directory in my project:

pc-morena:pytz lyudmilangelov$ cd zoneinfo/
pc-morena:zoneinfo lyudmilangelov$ ls -l
total 448
drwxr-xr-x@  55 lyudmilangelov  staff   1870 Nov 10 12:48 Africa
drwxr-xr-x@ 135 lyudmilangelov  staff   4590 Nov 10 12:48 America
drwxr-xr-x@  12 lyudmilangelov  staff    408 Nov 10 12:48 Antarctica
drwxr-xr-x@   3 lyudmilangelov  staff    102 Nov 10 12:48 Arctic
drwxr-xr-x@  93 lyudmilangelov  staff   3162 Nov 10 12:48 Asia
...

解决方案

In response to this problem, went a different tact from gae-pytz and I created pytz-appengine. In particular pytz-appengine puts all the timezone information into the ndb datastore.

The unit tests for pytz pass (at least as long as they pass upstream). The main motivation with pytz-appengine was to make it trivial to update the timezone database on demand. There is a build script build.py that does this automatically.

I welcome any feedback on.

这篇关于如何正确添加PyTZ到Google App Engine应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆