Write the alexa top1M zip file after download

pull/5/head
Xavier Claude 2016-08-03 15:52:28 +02:00
parent b856e9897c
commit 4075a58165
1 changed files with 3 additions and 0 deletions

View File

@ -10,6 +10,9 @@ alexa_url = "http://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
alexa_file = "top-1m.csv.zip" alexa_file = "top-1m.csv.zip"
user_agent = {"User-agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0"} user_agent = {"User-agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0"}
r = requests.get(alexa_url, headers=user_agent) r = requests.get(alexa_url, headers=user_agent)
with open(alexa_file, 'wb') as fd:
for chunk in r.iter_content(4096):
fd.write(chunk)
with zipfile.ZipFile(alexa_file, 'r') as alexa_lists: with zipfile.ZipFile(alexa_file, 'r') as alexa_lists:
for name in alexa_lists.namelist(): for name in alexa_lists.namelist():
if name == "top-1m.csv": if name == "top-1m.csv":