Skip to content

Instantly share code, notes, and snippets.

@tag1216
Last active January 12, 2017 12:12
Show Gist options
  • Save tag1216/92045604d3586ec0e1081d50b7a7b9e6 to your computer and use it in GitHub Desktop.
Save tag1216/92045604d3586ec0e1081d50b7a7b9e6 to your computer and use it in GitHub Desktop.
Qiita Advent Calendar 2016 で削除されたカレンダー
import re
import requests
import time
def main():
url = "http://qiita.com/sudoyu/items/0a51593b257f419aeb20.md"
print(url)
res = requests.get(url)
print("status code: {}".format(res.status_code))
if res.status_code != 200:
return
r = re.compile("^\* (.+)$")
calendar_urls = [m.group(1) for m in map(r.match, res.text.split("\n")) if m]
deleted_url = []
for idx, url in enumerate(calendar_urls):
time.sleep(0.2)
while True:
print("({:3d}/{:3d}) {} ... ".format(idx, len(calendar_urls), url), end="", flush=True)
status_code = requests.head(url).status_code
print(status_code, flush=True)
if status_code == 404:
deleted_url.append(url)
if status_code in [200, 404]:
break
print("retry...")
time.sleep(30)
print("--------\ndeleted calendars")
for url in deleted_url:
print(url)
if __name__ == "__main__":
main()
http://qiita.com/advent-calendar/2016/give_me_kareshi
http://qiita.com/advent-calendar/2016/gpd-win
http://qiita.com/advent-calendar/2016/it_event_de_jgc
http://qiita.com/advent-calendar/2016/holydisupute
http://qiita.com/advent-calendar/2016/rite
http://qiita.com/advent-calendar/2016/free_zankoku
http://qiita.com/advent-calendar/2016/test
http://qiita.com/advent-calendar/2016/enough
http://qiita.com/advent-calendar/2016/dena2
http://qiita.com/advent-calendar/2016/job2
http://qiita.com/advent-calendar/2016/yes-girlfriend
http://qiita.com/advent-calendar/2016/chat-bot
http://qiita.com/advent-calendar/2016/dena
http://qiita.com/advent-calendar/2016/muscle
http://qiita.com/advent-calendar/2016/poet
http://qiita.com/advent-calendar/2016/no-girlfriend-ml
http://qiita.com/advent-calendar/2016/no-girlfriend
http://qiita.com/advent-calendar/2016/job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment