File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515* [ Получение аудиозаписей (VkAudio)] ( ./get_all_audio.py )
1616* [ Составление клавиатуры для бота группы (VkKeyboard)] ( ./keyboard.py )
1717* [ Получение большого кол-ва объектов (VkTools)] ( ./get_full_wall.py )
18+ * [ Работа с Streaming] ( ./streaming.py )
1819* [ Работа с VkRequestsPool] ( ./requests_pool.py )
1920* [ Работа с прокси и использование таймаутов] ( ./proxies_timeout_retries.py )
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ import vk_api
3+ from vk_api .streaming import VkStreaming
4+
5+
6+ def main ():
7+ """ Пример использования streaming
8+ https://vk.com/dev/streaming_api_docs
9+ """
10+ vk = vk_api .VkApi (token = < Сервисный ключ доступа > )
11+ streaming = VkStreaming (vk )
12+
13+ streaming .delete_all_rules ()
14+
15+ streaming .add_rule ("квартира Москва" , "Квартиры" )
16+ streaming .add_rule ("купить гараж" , "Гаражи" )
17+
18+ for event in streaming .listen ():
19+ tags = '|' .join (event ['tags' ])
20+ print ("Теги: " + tags )
21+ print ("Запись: " + event ['event_url' ])
22+ print ("Текст: " + event ['text' ])
23+ print ("_____________________________________________________" )
24+
25+ if __name__ == '__main__' :
26+ main ()
Original file line number Diff line number Diff line change @@ -92,6 +92,10 @@ def delete_rule(self, tag):
9292 return True
9393 elif response ['code' ] == 400 :
9494 raise VkStreamingError (response ['error' ])
95+
96+ def delete_all_rules (self ):
97+ for item in self .get_rules ():
98+ self .delete_rule (item ['tag' ])
9599
96100 def listen (self ):
97101 """ Слушать сервер """
You can’t perform that action at this time.
0 commit comments