-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (27 loc) · 956 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import requests
import json, os
import zipfile
if __name__ == "__main__":
with open('config.json', 'r') as f:
str = f.read()
config = json.loads(str)
headers = config["headers"]
for task in config["tasks"]:
if "headers" in task:
headers = task["headers"]
else:
headers = config["headers"]
try:
with open(task["file_name"],"wb") as file:
response = requests.get(task["file_url"], stream=True, headers=headers, timeout=30)
for data in response.iter_content(chunk_size=1024*1024):
if data:
file.write(data)
response.close()
except Exception as e:
print(e)
f = zipfile.ZipFile(config["output"], 'w', zipfile.ZIP_DEFLATED)
for task in config["tasks"]:
f.write(task["file_name"], task["file_name"])
f.close()