snapshot_results.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:mccelections 作者: mcclatchy 项目源码 文件源码
def snapshot_to_json(self):
    now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')

    ## don't include trailing slash in path -- it's in fullpath

    ## server (change parent dir to fixtures, add that path to Django settings and just leave dated subdirectory)
    path = '/home/ubuntu/mccelections/electionsproject/snapshots/%s' % (election_date_string)

    filename = '%s' % (now)
    fullpath = '%s/%s.json' % (path, filename)

    snapshotresults = serializers.serialize('json', Result.objects.filter(election_date=election_date_string))

    f = open(fullpath, 'w')
    f.write(snapshotresults)
    f.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号