我正在尝试解析RSS提要.Feed中的条目包含以下日期元素:
<dc:date>2016-09-21T16:00:00+02:00</dc:date>
Run Code Online (Sandbox Code Playgroud)
使用feedparser,我尝试:
published_time = datetime.fromtimestamp(mktime(entry.published_parsed))
Run Code Online (Sandbox Code Playgroud)
但问题是我似乎得到了存储在数据库中的错误时间.在这种特殊情况下,日期时间存储为:
2016-09-21 13:00:00
Run Code Online (Sandbox Code Playgroud)
...当我期望14:00 - 正确的UTC时间.
我认为问题出在我们的django设置中,我们有:
TIME_ZONE = 'Europe/Berlin'
Run Code Online (Sandbox Code Playgroud)
因为当我切换到:
TIME_ZONE = 'UTC'
Run Code Online (Sandbox Code Playgroud)
...数据时间存储为正确的UTC时间:
2016-09-21 14:00:00
Run Code Online (Sandbox Code Playgroud)
有没有办法保持django设置不变,但要正确解析和存储这个日期时间,而不会影响django时区设置?
编辑:也许这样更清楚......
print entry.published_parsed
published_time = datetime.fromtimestamp(mktime(entry.published_parsed))
print published_time
localized_time = pytz.timezone(settings.TIME_ZONE).localize(published_time, is_dst=None)
print localized_time
time.struct_time(tm_year=2016, tm_mon=9, tm_mday=21, tm_hour=14, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=265, tm_isdst=0)
2016-09-21 15:00:00
2016-09-21 15:00:00+02:00
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Entrez将发布数据导入数据库.搜索部分工作正常,但当我尝试解析时:
from Bio import Entrez
def create_publication(pmid):
handle = Entrez.efetch("pubmed", id=pmid, retmode="xml")
records = Entrez.parse(handle)
item_data = records.next()
handle.close()
Run Code Online (Sandbox Code Playgroud)
...我收到以下错误:
文件"/venv/lib/python2.7/site-packages/Bio/Entrez/Parser.py",第296行,解析引发ValueError("XML文件不代表列表.请使用Entrez.read而不是Entrez .parse")ValueError:XML文件不代表列表.请使用Entrez.read而不是Entrez.parse
这段代码以前一直工作到几天前.有什么想法可能会出错吗?
此外,查看源代码(http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html)并尝试按照列出的示例,给出相同的错误:
from Bio import Entrez
Entrez.email = "Your.Name.Here@example.org"
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml")
records = Entrez.parse(handle)
for record in records:
print(record['MedlineCitation']['Article']['ArticleTitle'])
handle.close()
Run Code Online (Sandbox Code Playgroud) 我正在尝试将应用程序升级到Django 1.11,但是遇到了问题collectstatic。
旧版本:
django 1.8.17
django-storages 1.5.1
Run Code Online (Sandbox Code Playgroud)
新版本:
django 1.11.12
django-storages 1.6.6
Run Code Online (Sandbox Code Playgroud)
存储:
class StaticS3BotoStorage(ManifestFilesMixin, S3BotoStorage):
location = 'static'
file_overwrite = True
preload_metadata = True
Run Code Online (Sandbox Code Playgroud)
要么
class StaticS3BotoStorage(CachedFilesMixin, S3BotoStorage):
location = 'static'
file_overwrite = True
preload_metadata = True
Run Code Online (Sandbox Code Playgroud)
使用旧版本,可以collectstatic很好地工作,包括collectstatic --clear。
升级后,collectstatic --clear失败(不删除任何文件)。
collectstatic确实会复制文件,但是有时会创建同一文件的两个版本。在此特定示例中,我得到base.hash1.css和base.hash2.css。base.hash2.css为空,因此页面可以打开,但无法正确呈现。
如果我不使用CachedFilesMixin或ManifestFilesMixin,则collectstatic工作正常,但清除仍然失败。
我测试了django 1.11和django-storages的不同组合,但它们的行为似乎都相同。
有人遇到过类似的问题吗?