__init__.py 文件源码

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

项目:advent_of_code_2016 作者: kodsnack 项目源码 文件源码
def main(which_days):
    for day in which_days:
        day_input_file = os.path.join(root_dir, 'input_{0:02d}.txt'.format(day))
        if not os.path.exists(day_input_file):
            session_token = os.environ.get("AOC_SESSION_TOKEN")
            if session_token is None:
                raise ValueError("Must set AOC_SESSION_TOKEN environment variable!")
            url = 'https://adventofcode.com/2016/day/{0}/input'.format(day)
            opener = build_opener()
            opener.addheaders.append(('Cookie', 'session={0}'.format(session_token)))
            response = opener.open(url)
            with open(day_input_file, 'w') as f:
                f.write(response.read().decode("utf-8"))

        print("Solutions to Day {0:02d}\n-------------------".format(day))
        # Horrible way to run scripts, but I did not want to rewrite old solutions.
        day_module = __import__('{0:02d}'.format(day))
        print('')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号