-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
39 lines (31 loc) · 1006 Bytes
/
Copy pathlibrary.py
File metadata and controls
39 lines (31 loc) · 1006 Bytes
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
37
38
39
import requests
BASE_URL = 'https://raw.githubusercontent.com/ivanl-exe/library/main/catalog/'
def __format_name__(name: str) -> str:
if name[-4:].find('.py') == -1:
name += '.py'
return name
def __format_dir__(dir: str) -> str:
if dir.rfind('/') != len(dir) - 1:
dir += '/'
return dir
def borrow(filename: str) -> str:
url = ''.join([
__format_dir__(BASE_URL),
filename
])
for i in range(2):
response = requests.get(url)
if response.status_code != 200: return ''
if i == 1:
code = response.text
break
url = response.text
return code
def save(filename: str, save_directory: str = ''):
save_directory = ''.join([__format_dir__(save_directory), __format_name__(filename)])
code = borrow(filename)
file = open(save_directory, 'w')
file.write(
'\n'.join([l.replace(' ', '', 1) for l in code.split('\n') if l.find('class') == -1])
)
return code