import_stats.py 文件源码

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

项目:wiki_import 作者: DOsinga 项目源码 文件源码
def fetch_dumps(dump_dir, dumps_to_fetch):
  # don't try anything in the last month, it might not be online yet
  last_date = datetime.datetime.today() - datetime.timedelta(30)
  year = last_date.year
  if last_date.month <= 2:
    year -= 1
  if calendar.isleap(year):
    days = 366
  else:
    days = 365
  for i in range(dumps_to_fetch):
    local_path = None
    remote_path = None
    while not local_path or os.path.isdir(local_path):
      random_day = last_date - datetime.timedelta(days=random.randint(1, days))
      random_hour = random.randint(1, 24)
      d = {'year': random_day.year, 'month': random_day.month, 'day': random_day.day, 'hour': random_hour}
      remote_path = REMOTE_PATH % d
      local_path = os.path.join(dump_dir, LOCAL_PATH % d)
    print 'getting', local_path
    data = requests.get(remote_path).content
    with file(local_path, 'wb') as fout:
      fout.write(data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号