-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSHAREFILE_PYTHON.py
66 lines (46 loc) · 2.24 KB
/
SHAREFILE_PYTHON.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
57
58
59
60
61
62
63
64
65
66
import requests
class sharefile():
"""
this class implements sharefile's API
methods:
> auth - get autenticating token
> items - Get Root Items
"""
def dl(self,env:str,item_id,token,filepath:str):
headers = {
'Authorization': f'Bearer {token}',
}
response = requests.get(f'https://{env}.sf-api.com/sf/v3/Items({item_id})/Download', headers=headers, verify=False)
with open(filepath, 'wb') as f:
f.write(response.content)
return response.json()
def uploader(self,env:str,item_id,token,filepath:str):
headers = {
'Authorization': f'Bearer {token}',
}
res = requests.get(f'https://{env}.sf-api.com/sf/v3/Items({item_id})/Upload', headers=headers, verify=False)
f=dict(File1=open(file=filepath, 'rb'))
files = {
'File1': open(file=filepath, 'rb')
}
resp = requests.post(res, files=f, verify=False)
return resp.json()
def items(self,env:str,token):
headers = {
'Authorization': f'Bearer {token}',
}
res = requests.get(f'https://{env}.sf-api.com/sf/v3/Items', headers=headers, verify=False)
return res.json()
def index(self,env:str,creds=None,comm=None):
res = requests.get(f'https://{env}.sf-api.com/sf/v3')
print(res)
return res.json()
def auth(self,env:str,creds={"USERNAME":"my@user.name","PASSWORD":'mypassword',"CLIENT_ID":"myclient-id","myclient-SECRET":"myclient-secret"},comm="Shares"):
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = f'grant_type=password&client_id={creds["CLIENT_ID"]}&client_secret=creds["myclient-SECRET"]&username=creds["USERNAME"]&password=creds["PASSWORD"]'
T = requests.post(f'https://{env}.sharefile.com/oauth/token', headers=headers, data=data)
return T.json()
print(sharefile.index("weankor"))
print(sharefile.auth("weankor",creds={"USERNAME":"my@user.name","PASSWORD":'mypassword',"CLIENT_ID":"myclient-id","myclient-SECRET":"myclient-secret"}))