-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs_downloader.py
36 lines (32 loc) · 1.25 KB
/
docs_downloader.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
35
36
from os.path import dirname
docs_path = "docs\\"
_docs_path = dirname(__file__)+"/"+docs_path
from utils import load_json, check_if_exists
def download_docs(src):
import requests
j = load_json(f"/docs_structures/{src}.json")
base = j['base_url']
docs_to_download = j['files']
for link in docs_to_download:
print("Downloading", link)
r = requests.get(base + link)
if "/" in link:
check_if_exists(docs_path + link.split("/")[0])
#with open(_docs_path + link.replace("/", "\\"), "wb") as file:
# file.write(r.content)
with open(_docs_path + "discord.md", "ab") as file:
file.write(r.content)
if __name__ == "__main__":
import sys
try:
src = sys.argv[1]
download_docs(src)
except:
import glob
from os.path import dirname
_o = glob.glob(dirname(__file__) + '/docs_structures/**/*', recursive=True)
structures = '- ' + '\n- '.join([i.replace('\\', ' / ').split(' / ')[-1].split('. ')[0] for i in _o])
if len(_o) == 1:
download_docs(_o[0].replace('\\', ' / ').split(' / ')[-1].split('.')[0])
else:
print('Specify json from docs_structures to use\n\tAvailable structures:\n'+structures)