-
Notifications
You must be signed in to change notification settings - Fork 0
/
curlgoogle.sh
executable file
·51 lines (42 loc) · 1.52 KB
/
curlgoogle.sh
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
#!/usr/bin/python
'''
A quick python script to automate curl->googledrive interfacing
This should require nothing more than the system python version and curl. Written for python2.7 (with 3 in mind).Dan Ellis 2020
'''
import os,sys,json
if sys.version[0]=='3':
raw_input = lambda(x): input(x)
##############################
#Owner information goes here!#
##############################
name = 'curldata'
client_id= 'x.apps.googleusercontent.com'
client_secret='x'
##############################
cmd1 = json.loads(os.popen('curl -d "client_id=%s&
scope=https://www.googleapis.com/auth/drive.file"
https://oauth2.googleapis.com/device/code'%client_id).read())
str(raw_input('\n Enter %(user_code)s\n\n at %(verification_url)s
\n\n Then hit Enter to continue.'%cmd1))
str(raw_input('(twice)'))
cmd2 = json.loads(os.popen(('curl -d client_id=%s -d
client_secret=%s -d device_code=%s -d grant_type=urn~~3Aietf~~3Aparams~~3Aoauth~~3Agrant-
type~~3Adevice_code https://accounts.google.com/o/oauth2/token'%
(client_id,client_secret,cmd1['device_code'])).replace('~~','%')).
read())
print(cmd2)
# zip files
cmd3 = os.popen('zip -r %s.zip %s'%(name,'
'.join(sys.argv[1:]))).read
print(cmd3)
cmd4 = os.popen('''
curl -X POST -L \
-H "Authorization: Bearer %s" \
-F "metadata={name :\'%s\'};type=application/json;
charset=UTF-8" \
-F "file=@%s.zip;type=application/zip" \
"https://www.googleapis.com/upload/drive
/v3/files?uploadType=multipart"
'''%(cmd2["access_token"],name,name)).read()
print(cmd4)
print('end')