-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfunction.py
More file actions
79 lines (68 loc) · 2.68 KB
/
function.py
File metadata and controls
79 lines (68 loc) · 2.68 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests, configparser, sys, os
# sys func
def exit(err):
sys.exit(err)
if not os.path.isfile('config.ini'):
print('Missing config file! Please read tutorial and create a config file.')
exit(0)
def myParser(path = 'config.ini'):
ps = configparser.ConfigParser()
ps.read(path)
return ps
def toDict(self, get = 'All'):
d = dict(self._sections)
for k in d:
d[k] = dict(self._defaults, **d[k])
d[k].pop('__name__', None)
return d if get == 'All' else d[get]
def errorInfo(error_code):
ec = str(error_code)
i = {
'405': '-> Wrong Password, please edit correct information config',
'406': '-> Account not activated',
'409': '-> Account is locked login',
'410': '-> Account is locked login',
'424': '-> You entered wrong password 3 times, please enter again after 10 minutes',
'201': '-> Not logged in yet! Please rerun login file!'
}
return i[ec] if ec in i else "Unknown Error"
def rq_fshare(type = 'POST', URL = '', header = {}, Data = {}):
return requests.post(url = URL, headers = header, json = Data)
def requestToJson(self):
import json
return json.loads(json.dumps(self.json()))
def chunk_download(furl, name, folder = 'downloaded/'):
import math, enlighten
url = furl
fname = name
# Should be one global variable
MANAGER = enlighten.get_manager()
r = requests.get(url, stream = True)
assert r.status_code == 200, r.status_code
dlen = int(r.headers.get('Content-Length', '0')) or None
print("-> File Size: ", "{:.2f}".format(dlen/(2**20)/1024),"GB (" + str(math.ceil(dlen/2**20)), "MB)")
with MANAGER.counter(color = 'green', total = dlen and math.ceil(dlen / 2 ** 20), unit = 'MiB', leave = False) as ctr, \
open(folder + fname, 'wb', buffering = 2 ** 24) as f:
for chunk in r.iter_content(chunk_size = 2 ** 20):
# print(chunk[-16:].hex().upper())
f.write(chunk)
ctr.update()
return fname
def pushToDrive(file = '', path = ''):
import os
print("gdrive upload -p " + path + " '" + file + "'")
with os.popen("gdrive upload -p " + path + " '" + file + "'") as f:
print(f.readlines())
#debug
def pushToOneDrive(file = '', remotename ='', path = ''):
import os
cmd = "rclone copy '" + file + "' " + remotename + ":" + path + " --drive-acknowledge-abuse --drive-keep-revision-forever --drive-use-trash=false"
print(cmd)
with os.popen(cmd) as f:
print(f.readlines())
def removeFile(file = ''):
import os
print("-> Deleting local File...")
# print("rm -rf " + "'" + file + "'")
# os.popen("rm -rf " + "'" + file + "'")
os.remove(file)