-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_to_mega.py
More file actions
55 lines (49 loc) · 1.41 KB
/
upload_to_mega.py
File metadata and controls
55 lines (49 loc) · 1.41 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
from mega import Mega
import os
import sys
email = ''
password = ''
directory = 'files'
folder_to_upload = 'uploads'
def login_to_mega(email,password):
try:
print('Trying to login in your account')
mega = Mega()
m = mega.login(email, password)
print('Login successful')
return m
except:
print('Bad login!')
sys.exit(0)
def get_all_files_to_upload():
print('Listing files to upload...')
try:
dir_list = [f for f in os.listdir(directory) if not f.startswith('.')]
return dir_list
except Exception as error:
print('Error: ',error)
def upload_files(list,m):
if len(list)==0:
print('No files to upload')
sys.exit(0)
try:
folder = m.find(folder_to_upload)
print("Uploading files...")
for f in list:
upload_file = directory + '/' + f
file = m.upload(upload_file, folder[0])
print(f,' successfully uploaded')
return "All files uploaded sucessfully"
except Exception as error:
print('Error: ',error)
if __name__ == "__main__":
try:
m = login_to_mega(email,password)
list = get_all_files_to_upload()
result = upload_files(list,m)
print(result)
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
sys.exit(0)
except:
print("Something else went wrong")