election_auto_w_gdoc.py 文件源码

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

项目:mccelections 作者: mcclatchy 项目源码 文件源码
def snapshot(electiondate_string):
    ## *** need to have this on S3 or other external location to not fill up server ***
        ## NOTE: instead of saving anew, just use/copy the tmp file?
        ## should we snapshot manual results from gdoc? use separate parent dir to avoid conflict
    if mccelectionsenv == "local":
        # call_command('snapshot_results')
        ## copy and rename results.csv w/ cp command
        file_path = os.environ["SAVER_PATH"]
        orgin = file_path + "/tmp/results.csv"
        now = timezone.localtime(timezone.now())
        save_date = now.date()
        save_date_string = str(save_date)
        timestamp = now.strftime('%Y-%m-%d_%H-%M-%S')

        snapshot_filename = "results%s.csv" % (timestamp)
        destination_dir = "%s/%s/%s" % (file_path, electiondate_string, save_date_string)
        destination = "%s/%s" % (destination_dir, snapshot_filename)

        mkdir = "mkdir -p %s" % (destination_dir)
        snapshot = "cp %s %s" % (origin, destination)

        ## making the dir, if it's not there
        call(mkdir, shell=True)
        message = "Making new directory, if needed:\n%s" % (destination_dir)
        slackbot(message)
        ## actual snapshot executed
        call(snapshot, shell=True)
        message = "Snapshotting"
        slackbot(message)
    # else:
        # snapshot to S3
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号