/
newsfeed.py
488 lines (426 loc) · 19.8 KB
/
newsfeed.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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# Generated with love
import typing
from vkbottle.types import responses
from .access import APIAccessibility
from .method import BaseMethod
class NewsfeedAddBan(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, user_ids: typing.List = None, group_ids: typing.List = None
) -> responses.ok_response.OkResponse:
""" newsfeed.addBan
From Vk Docs: Prevents news from specified users and communities from appearing in the current user's newsfeed.
Access from user token(s)
:param user_ids:
:param group_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(
"newsfeed.addBan",
params,
response_model=responses.ok_response.OkResponseModel,
)
class NewsfeedDeleteBan(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, user_ids: typing.List = None, group_ids: typing.List = None
) -> responses.ok_response.OkResponse:
""" newsfeed.deleteBan
From Vk Docs: Allows news from previously banned users and communities to be shown in the current user's newsfeed.
Access from user token(s)
:param user_ids:
:param group_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(
"newsfeed.deleteBan",
params,
response_model=responses.ok_response.OkResponseModel,
)
class NewsfeedDeleteList(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(self, list_id: int) -> responses.ok_response.OkResponse:
""" newsfeed.deleteList
From Vk Docs:
Access from user token(s)
:param list_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(
"newsfeed.deleteList",
params,
response_model=responses.ok_response.OkResponseModel,
)
class NewsfeedGet(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
filters: typing.List = None,
return_banned: bool = None,
start_time: int = None,
end_time: int = None,
max_photos: int = None,
source_ids: str = None,
start_from: str = None,
count: int = None,
fields: typing.List = None,
section: str = None,
) -> responses.newsfeed.Get:
""" newsfeed.get
From Vk Docs: Returns data required to show newsfeed for the current user.
Access from user token(s)
:param filters: Filters to apply: 'post' — new wall posts, 'photo' — new photos, 'photo_tag' — new photo tags, 'wall_photo' — new wall photos, 'friend' — new friends, 'note' — new notes
:param return_banned: '1' — to return news items from banned sources
:param start_time: Earliest timestamp (in Unix time) of a news item to return. By default, 24 hours ago.
:param end_time: Latest timestamp (in Unix time) of a news item to return. By default, the current time.
:param max_photos: Maximum number of photos to return. By default, '5'.
:param source_ids: Sources to obtain news from, separated by commas. User IDs can be specified in formats '' or 'u' , where '' is the user's friend ID. Community IDs can be specified in formats '-' or 'g' , where '' is the community ID. If the parameter is not set, all of the user's friends and communities are returned, except for banned sources, which can be obtained with the [vk.com/dev/newsfeed.getBanned|newsfeed.getBanned] method.
:param start_from: identifier required to get the next page of results. Value for this parameter is returned in 'next_from' field in a reply.
:param count: Number of news items to return (default 50, maximum 100). For auto feed, you can use the 'new_offset' parameter returned by this method.
:param fields: Additional fields of [vk.com/dev/fields|profiles] and [vk.com/dev/fields_groups|communities] to return.
:param section:
"""
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(
"newsfeed.get", params, response_model=responses.newsfeed.GetModel
)
class NewsfeedGetBanned(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, extended: bool = None, fields: typing.List = None, name_case: str = None
) -> responses.newsfeed.GetBanned:
""" newsfeed.getBanned
From Vk Docs: Returns a list of users and communities banned from the current user's newsfeed.
Access from user token(s)
:param extended: '1' — return extra information about users and communities
:param fields: Profile fields to return.
:param name_case: Case for declension of user name and surname: 'nom' — nominative (default), 'gen' — genitive , 'dat' — dative, 'acc' — accusative , 'ins' — instrumental , 'abl' — prepositional
"""
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(
"newsfeed.getBanned",
params,
response_model=responses.newsfeed.GetBannedModel,
)
class NewsfeedGetComments(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
count: int = None,
filters: typing.List = None,
reposts: str = None,
start_time: int = None,
end_time: int = None,
last_comments_count: int = None,
start_from: str = None,
fields: typing.List = None,
) -> responses.newsfeed.GetComments:
""" newsfeed.getComments
From Vk Docs: Returns a list of comments in the current user's newsfeed.
Access from user token(s)
:param count: Number of comments to return. For auto feed, you can use the 'new_offset' parameter returned by this method.
:param filters: Filters to apply: 'post' — new comments on wall posts, 'photo' — new comments on photos, 'video' — new comments on videos, 'topic' — new comments on discussions, 'note' — new comments on notes,
:param reposts: Object ID, comments on repost of which shall be returned, e.g. 'wall1_45486'. (If the parameter is set, the 'filters' parameter is optional.),
:param start_time: Earliest timestamp (in Unix time) of a comment to return. By default, 24 hours ago.
:param end_time: Latest timestamp (in Unix time) of a comment to return. By default, the current time.
:param last_comments_count:
:param start_from: Identificator needed to return the next page with results. Value for this parameter returns in 'next_from' field.
:param fields: Additional fields of [vk.com/dev/fields|profiles] and [vk.com/dev/fields_groups|communities] 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(
"newsfeed.getComments",
params,
response_model=responses.newsfeed.GetCommentsModel,
)
class NewsfeedGetLists(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, list_ids: typing.List = None, extended: bool = None
) -> responses.newsfeed.GetLists:
""" newsfeed.getLists
From Vk Docs: Returns a list of newsfeeds followed by the current user.
Access from user token(s)
:param list_ids: numeric list identifiers.
:param extended: Return additional list info
"""
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(
"newsfeed.getLists", params, response_model=responses.newsfeed.GetListsModel
)
class NewsfeedGetMentions(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
owner_id: int = None,
start_time: int = None,
end_time: int = None,
offset: int = None,
count: int = None,
) -> responses.newsfeed.GetMentions:
""" newsfeed.getMentions
From Vk Docs: Returns a list of posts on user walls in which the current user is mentioned.
Access from user token(s)
:param owner_id: Owner ID.
:param start_time: Earliest timestamp (in Unix time) of a post to return. By default, 24 hours ago.
:param end_time: Latest timestamp (in Unix time) of a post to return. By default, the current time.
:param offset: Offset needed to return a specific subset of posts.
:param count: Number of posts 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(
"newsfeed.getMentions",
params,
response_model=responses.newsfeed.GetMentionsModel,
)
class NewsfeedGetRecommended(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
start_time: int = None,
end_time: int = None,
max_photos: int = None,
start_from: str = None,
count: int = None,
fields: typing.List = None,
) -> responses.newsfeed.GetRecommended:
""" newsfeed.getRecommended
From Vk Docs: , Returns a list of newsfeeds recommended to the current user.
Access from user token(s)
:param start_time: Earliest timestamp (in Unix time) of a news item to return. By default, 24 hours ago.
:param end_time: Latest timestamp (in Unix time) of a news item to return. By default, the current time.
:param max_photos: Maximum number of photos to return. By default, '5'.
:param start_from: 'new_from' value obtained in previous call.
:param count: Number of news items to return.
:param fields: Additional fields of [vk.com/dev/fields|profiles] and [vk.com/dev/fields_groups|communities] 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(
"newsfeed.getRecommended",
params,
response_model=responses.newsfeed.GetRecommendedModel,
)
class NewsfeedGetSuggestedSources(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
offset: int = None,
count: int = None,
shuffle: bool = None,
fields: typing.List = None,
) -> responses.newsfeed.GetSuggestedSources:
""" newsfeed.getSuggestedSources
From Vk Docs: Returns communities and users that current user is suggested to follow.
Access from user token(s)
:param offset: offset required to choose a particular subset of communities or users.
:param count: amount of communities or users to return.
:param shuffle: shuffle the returned list or not.
:param fields: list of extra fields to be returned. See available fields for [vk.com/dev/fields|users] and [vk.com/dev/fields_groups|communities].
"""
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(
"newsfeed.getSuggestedSources",
params,
response_model=responses.newsfeed.GetSuggestedSourcesModel,
)
class NewsfeedIgnoreItem(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, type: str, item_id: int, owner_id: int
) -> responses.ok_response.OkResponse:
""" newsfeed.ignoreItem
From Vk Docs: Hides an item from the newsfeed.
Access from user token(s)
:param type: Item type. Possible values: *'wall' – post on the wall,, *'tag' – tag on a photo,, *'profilephoto' – profile photo,, *'video' – video,, *'audio' – audio.
:param owner_id: Item owner's identifier (user or community), "Note that community id must be negative. 'owner_id=1' – user , 'owner_id=-1' – community "
:param item_id: Item identifier
"""
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(
"newsfeed.ignoreItem",
params,
response_model=responses.ok_response.OkResponseModel,
)
class NewsfeedSaveList(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self,
title: str,
list_id: int = None,
source_ids: typing.List = None,
no_reposts: bool = None,
) -> responses.newsfeed.SaveList:
""" newsfeed.saveList
From Vk Docs: Creates and edits user newsfeed lists
Access from user token(s)
:param list_id: numeric list identifier (if not sent, will be set automatically).
:param title: list name.
:param source_ids: users and communities identifiers to be added to the list. Community identifiers must be negative numbers.
:param no_reposts: reposts display on and off ('1' is for off).
"""
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(
"newsfeed.saveList", params, response_model=responses.newsfeed.SaveListModel
)
class NewsfeedSearch(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [
APIAccessibility.USER,
APIAccessibility.SERVICE,
]
async def __call__(
self,
q: str = None,
extended: bool = None,
count: int = None,
latitude: typing.Any = None,
longitude: typing.Any = None,
start_time: int = None,
end_time: int = None,
start_from: str = None,
fields: typing.List = None,
) -> responses.newsfeed.Search:
""" newsfeed.search
From Vk Docs: Returns search results by statuses.
Access from user, service token(s)
:param q: Search query string (e.g., 'New Year').
:param extended: '1' — to return additional information about the user or community that placed the post.
:param count: Number of posts to return.
:param latitude: Geographical latitude point (in degrees, -90 to 90) within which to search.
:param longitude: Geographical longitude point (in degrees, -180 to 180) within which to search.
:param start_time: Earliest timestamp (in Unix time) of a news item to return. By default, 24 hours ago.
:param end_time: Latest timestamp (in Unix time) of a news item to return. By default, the current time.
:param start_from:
:param fields: Additional fields of [vk.com/dev/fields|profiles] and [vk.com/dev/fields_groups|communities] 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(
"newsfeed.search", params, response_model=responses.newsfeed.SearchModel
)
class NewsfeedUnignoreItem(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, type: str, item_id: int, owner_id: int
) -> responses.ok_response.OkResponse:
""" newsfeed.unignoreItem
From Vk Docs: Returns a hidden item to the newsfeed.
Access from user token(s)
:param type: Item type. Possible values: *'wall' – post on the wall,, *'tag' – tag on a photo,, *'profilephoto' – profile photo,, *'video' – video,, *'audio' – audio.
:param owner_id: Item owner's identifier (user or community), "Note that community id must be negative. 'owner_id=1' – user , 'owner_id=-1' – community "
:param item_id: Item identifier
"""
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(
"newsfeed.unignoreItem",
params,
response_model=responses.ok_response.OkResponseModel,
)
class NewsfeedUnsubscribe(BaseMethod):
kwargs: dict = {}
access_token_type: APIAccessibility = [APIAccessibility.USER]
async def __call__(
self, type: str, item_id: int, owner_id: int = None
) -> responses.ok_response.OkResponse:
""" newsfeed.unsubscribe
From Vk Docs: Unsubscribes the current user from specified newsfeeds.
Access from user token(s)
:param type: Type of object from which to unsubscribe: 'note' — note, 'photo' — photo, 'post' — post on user wall or community wall, 'topic' — topic, 'video' — video
:param owner_id: Object owner ID.
:param item_id: Object 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(
"newsfeed.unsubscribe",
params,
response_model=responses.ok_response.OkResponseModel,
)
class Newsfeed:
def __init__(self, request):
self.add_ban = NewsfeedAddBan(request)
self.delete_ban = NewsfeedDeleteBan(request)
self.delete_list = NewsfeedDeleteList(request)
self.get = NewsfeedGet(request)
self.get_banned = NewsfeedGetBanned(request)
self.get_comments = NewsfeedGetComments(request)
self.get_lists = NewsfeedGetLists(request)
self.get_mentions = NewsfeedGetMentions(request)
self.get_recommended = NewsfeedGetRecommended(request)
self.get_suggested_sources = NewsfeedGetSuggestedSources(request)
self.ignore_item = NewsfeedIgnoreItem(request)
self.save_list = NewsfeedSaveList(request)
self.search = NewsfeedSearch(request)
self.unignore_item = NewsfeedUnignoreItem(request)
self.unsubscribe = NewsfeedUnsubscribe(request)