-
Notifications
You must be signed in to change notification settings - Fork 1
/
OkDownloader.py
74 lines (62 loc) · 3.24 KB
/
OkDownloader.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
67
68
69
70
71
72
73
74
import requests
from VkDownloader import VkDownloader
from hashlib import md5
import configparser
class OkDownloader(VkDownloader):
def __init__(self, profile_id, ya_token, google_token, progress_bar):
"""
:param profile_id: ok's page id
:param ya_token: token for yandex drive
:param google_token: token for google drive
:param progress_bar: progress bar in GUI
"""
super().__init__(profile_id, ya_token, google_token, progress_bar)
config = configparser.ConfigParser()
config.read('settings.ini')
self.ok_app_id = config['Ok']['app_id']
self.ok_app_key = config['Ok']['app_key']
self.ok_access_token = config['Ok']['access_token']
self.ok_secret_session_key = config['Ok']['secret_session_key']
self.respond = None
def upload_profile_photos_to_cloud_storage(self, number_of_photos, folder='ok_profile_photos'):
super().upload_profile_photos_to_cloud_storage(number_of_photos, folder)
def upload_album_photos_to_cloud_storage(self, album_id, number_of_photos, folder='ok_album_photos'):
super().upload_album_photos_to_cloud_storage(album_id, number_of_photos, folder)
def _get_profile_photos_data(self, number_of_photos):
sig_params = [f'application_id={self.ok_app_id}',
f'application_key={self.ok_app_key}',
f'fid={self.profile_id}',
f'count={number_of_photos}',
f'fields=photo.created_ms, photo.like_count, '
f'photo.pic_max, photo.standard_height, photo.standard_width'
]
sig = md5((''.join(sorted(sig_params)) + self.ok_secret_session_key).encode())
param = {
'application_id': f'{self.ok_app_id}',
'application_key': f'{self.ok_app_key}',
'access_token': f'{self.ok_access_token}',
'sig': str(sig),
'fid': f'{self.profile_id}',
'count': f'{number_of_photos}',
'fields': 'photo.created_ms, photo.like_count, photo.pic_max, photo.standard_height, photo.standard_width'
}
self.respond = requests.get('https://api.ok.ru/api/photos/getPhotos', params=param)
def _get_album_photos_data(self, album_id, number_of_photos):
sig_params = [f'application_id={self.ok_app_id}',
f'application_key={self.ok_app_key}',
f'aid={album_id}',
f'count={number_of_photos}'
f'fields=photo.created_ms, photo.like_count, '
f'photo.pic_max, photo.standard_height, photo.standard_width'
]
sig = md5((''.join(sorted(sig_params)) + self.ok_secret_session_key).encode())
param = {
'application_id': f'{self.ok_app_id}',
'application_key': f'{self.ok_app_key}',
'access_token': f'{self.ok_access_token}',
'sig': str(sig),
'aid': f'{album_id}',
'count': f'{number_of_photos}',
'fields': 'photo.created_ms, photo.like_count, photo.pic_max, photo.standard_height, photo.standard_width'
}
self.respond = requests.get('https://api.ok.ru/api/photos/getPhotos', params=param)