/
database.py
391 lines (341 loc) · 12.7 KB
/
database.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# Generated with love
import typing
from vkbottle.types import responses
from .access import APIAccessibility
from .method import BaseMethod
class DatabaseGetChairs(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, faculty_id: int, offset: int = None, count: int = None
) -> responses.database.GetChairs:
""" database.getChairs
From Vk Docs: Returns list of chairs on a specified faculty.
Access from user, service token(s)
:param faculty_id: id of the faculty to get chairs from
:param offset: offset required to get a certain subset of chairs
:param count: amount of chairs to get
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getChairs",
params,
response_model=responses.database.GetChairsModel,
)
class DatabaseGetCities(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
country_id: int,
region_id: int = None,
q: str = None,
need_all: bool = None,
offset: int = None,
count: int = None,
) -> responses.database.GetCities:
""" database.getCities
From Vk Docs: Returns a list of cities.
Access from user token(s)
:param country_id: Country ID.
:param region_id: Region ID.
:param q: Search query.
:param need_all: '1' — to return all cities in the country, '0' — to return major cities in the country (default),
:param offset: Offset needed to return a specific subset of cities.
:param count: Number of cities to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getCities",
params,
response_model=responses.database.GetCitiesModel,
)
class DatabaseGetCitiesById(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, city_ids: typing.List = None
) -> responses.database.GetCitiesById:
""" database.getCitiesById
From Vk Docs: Returns information about cities by their IDs.
Access from user, service token(s)
:param city_ids: City IDs.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getCitiesById",
params,
response_model=responses.database.GetCitiesByIdModel,
)
class DatabaseGetCountries(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
need_all: bool = None,
code: str = None,
offset: int = None,
count: int = None,
) -> responses.database.GetCountries:
""" database.getCountries
From Vk Docs: Returns a list of countries.
Access from user token(s)
:param need_all: '1' — to return a full list of all countries, '0' — to return a list of countries near the current user's country (default).
:param code: Country codes in [vk.com/dev/country_codes|ISO 3166-1 alpha-2] standard.
:param offset: Offset needed to return a specific subset of countries.
:param count: Number of countries to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getCountries",
params,
response_model=responses.database.GetCountriesModel,
)
class DatabaseGetCountriesById(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, country_ids: typing.List = None
) -> responses.database.GetCountriesById:
""" database.getCountriesById
From Vk Docs: Returns information about countries by their IDs.
Access from user, service token(s)
:param country_ids: Country IDs.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getCountriesById",
params,
response_model=responses.database.GetCountriesByIdModel,
)
class DatabaseGetFaculties(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, university_id: int, offset: int = None, count: int = None
) -> responses.database.GetFaculties:
""" database.getFaculties
From Vk Docs: Returns a list of faculties (i.e., university departments).
Access from user, service token(s)
:param university_id: University ID.
:param offset: Offset needed to return a specific subset of faculties.
:param count: Number of faculties to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getFaculties",
params,
response_model=responses.database.GetFacultiesModel,
)
class DatabaseGetMetroStations(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, city_id: int, offset: int = None, count: int = None, extended: bool = None
) -> responses.database.GetMetroStations:
""" database.getMetroStations
From Vk Docs: Get metro stations by city
Access from user, service token(s)
:param city_id:
:param offset:
:param count:
:param extended:
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getMetroStations",
params,
response_model=responses.database.GetMetroStationsModel,
)
class DatabaseGetMetroStationsById(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, station_ids: typing.List = None
) -> responses.database.GetMetroStationsById:
""" database.getMetroStationsById
From Vk Docs: Get metro station by his id
Access from user, service token(s)
:param station_ids:
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getMetroStationsById",
params,
response_model=responses.database.GetMetroStationsByIdModel,
)
class DatabaseGetRegions(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, country_id: int, q: str = None, offset: int = None, count: int = None
) -> responses.database.GetRegions:
""" database.getRegions
From Vk Docs: Returns a list of regions.
Access from user, service token(s)
:param country_id: Country ID, received in [vk.com/dev/database.getCountries|database.getCountries] method.
:param q: Search query.
:param offset: Offset needed to return specific subset of regions.
:param count: Number of regions to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getRegions",
params,
response_model=responses.database.GetRegionsModel,
)
class DatabaseGetSchoolClasses(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, country_id: int = None
) -> responses.database.GetSchoolClasses:
""" database.getSchoolClasses
From Vk Docs: Returns a list of school classes specified for the country.
Access from user, service token(s)
:param country_id: Country ID.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getSchoolClasses",
params,
response_model=responses.database.GetSchoolClassesModel,
)
class DatabaseGetSchools(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self, city_id: int, q: str = None, offset: int = None, count: int = None
) -> responses.database.GetSchools:
""" database.getSchools
From Vk Docs: Returns a list of schools.
Access from user, service token(s)
:param q: Search query.
:param city_id: City ID.
:param offset: Offset needed to return a specific subset of schools.
:param count: Number of schools to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getSchools",
params,
response_model=responses.database.GetSchoolsModel,
)
class DatabaseGetUniversities(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self,
q: str = None,
country_id: int = None,
city_id: int = None,
offset: int = None,
count: int = None,
) -> responses.database.GetUniversities:
""" database.getUniversities
From Vk Docs: Returns a list of higher education institutions.
Access from user, service token(s)
:param q: Search query.
:param country_id: Country ID.
:param city_id: City ID.
:param offset: Offset needed to return a specific subset of universities.
:param count: Number of universities to return.
"""
params = {
k if not k.endswith("_") else k[:-1]: v
for k, v in {**locals(), **self.kwargs}.items()
if k not in ["self"] and v is not None
}
return await self.request(
"database.getUniversities",
params,
response_model=responses.database.GetUniversitiesModel,
)
class Database:
def __init__(self, request):
self.get_chairs = DatabaseGetChairs(request)
self.get_cities = DatabaseGetCities(request)
self.get_cities_by_id = DatabaseGetCitiesById(request)
self.get_countries = DatabaseGetCountries(request)
self.get_countries_by_id = DatabaseGetCountriesById(request)
self.get_faculties = DatabaseGetFaculties(request)
self.get_metro_stations = DatabaseGetMetroStations(request)
self.get_metro_stations_by_id = DatabaseGetMetroStationsById(request)
self.get_regions = DatabaseGetRegions(request)
self.get_school_classes = DatabaseGetSchoolClasses(request)
self.get_schools = DatabaseGetSchools(request)
self.get_universities = DatabaseGetUniversities(request)