-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiProcessing.py
46 lines (37 loc) · 1.33 KB
/
apiProcessing.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
import json
import requests
from repositories import downloadPhoto
class photo:
def getUrl(self, item):
phtoUrl = ""
try:
photoUrl = item['photo']['photo_1280']
print("hight quality")
except:
try:
photoUrl = item['photo']['photo_807']
print("meddle quality")
except:
photoUrl = item['photo']['photo_604']
print("low quality")
return photoUrl
def getPhoto(self, attachments):
photos_path = []
for item in attachments:
if item['type'] == 'photo':
photoUrl = self.getUrl(item)
print(photoUrl)
path = downloadPhoto(photoUrl)
photos_path.append(path)
return photos_path
def uploadDoc(api,token,path,title):
maratik = 313941939
upload_url = api.docs.getMessagesUploadServer(access_token=token, type='doc', peer_id=maratik)['upload_url']
response = requests.post(upload_url, files={'file': open(path, 'rb')})
result = json.loads(response.content)
file = result['file']
json1 = api.docs.save(access_token=token, file=file, title=title, tags=[])[0]
owner_id = json1['owner_id']
photo_id = json1['id']
attach = 'doc' + str(owner_id) + '_' + str(photo_id)
return attach