/
upload.py
56 lines (47 loc) · 1.4 KB
/
upload.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pydrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import os.path
import shutil
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("file_name")
parser.add_argument("upload_dir")
args = parser.parse_args()
# Zip Rom and Wad
shutil.make_archive(args.upload_dir, 'zip', args.upload_dir)
# Authenticate
gauth = GoogleAuth()
if os.path.isfile('credentials.json'):
gauth.LoadCredentialsFile('credentials.json')
if gauth.credentials is None:
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
try:
gauth.Refresh()
except pydrive.auth.RefreshError:
gauth.LocalWebserverAuth()
else:
gauth.Authorize()
gauth.SaveCredentialsFile('credentials.json')
# Upload
drive = GoogleDrive(gauth)
upload_file = drive.CreateFile({'title': args.file_name})
upload_file.SetContentFile(args.upload_dir + '.zip')
upload_file.Upload()
# Share with everyone
upload_file['id']
upload_file.InsertPermission({
'type': 'anyone',
'value': 'anyone',
'role': 'reader'
})
# Create share link
link = upload_file['alternateLink']
link=link.split('?')[0]
link=link.split('/')[-2]
link='https://docs.google.com/uc?export=download&id='+link
print(link)
if __name__ == "__main__":
main()