Beispiel #1
0
import json
import requests
from vkstreaming import Streaming

app_vkid = 6712606
servise_token = "64da4c8064da4c8064da4c803464bc219e664da64da4c803f6dc6be3497baa33cf902f8"

session = vk_api.VkApi(token=servise_token,
                       api_version="5.85",
                       app_id=app_vkid)
vk = session.get_api()
respone = vk.streaming.getServerUrl()

streamingAPI = Streaming(respone["endpoint"], respone["key"])
streamingAPI.del_all_rules()
rules = streamingAPI.get_rules()
streamingAPI.add_rules("1", "мегафон")


@streamingAPI.stream
def my_func(event):

    event_type = event["event_type"]
    print("event type:: ", event_type)

    if event_type == 'comment' or event_type == 'post':

        author = event['author']
        author_url = author['author_url']
        if author['author_url'][15:17] == "id":
            person = list(
Beispiel #2
0
from vkstreaming import Streaming
import vkstreaming

response = vkstreaming.getServerUrl('3af6043f3af6043f3af6043f783aa93cb333af63af6043f6301786bc51f61b908819df3')
api = Streaming(response["endpoint"], response["key"])

api.del_all_rules()
for line in open('/Users/martikvm/PycharmProjects/DoubleSearch/popular_words_100_1.txt'):
    api.add_rules(line.lower(), line)
# api.add_rules('Сегодня', 'сегодня')

rules = api.get_rules()
for rule in rules:
    print(("{tag:15}:{value}").format(**rule))

@api.stream
def my_func(event):
    print("[{}]: {}".format(event['author']['id'], event['text']))

api.start()
# -*- coding: utf-8 -*-

from vkstreaming import getServerUrl, Streaming
from config import SERVICE_TOKEN, TG_TOKEN
from data import db, check_duplicates
from processing_module import process_text_vk

response = getServerUrl(SERVICE_TOKEN)
api = Streaming("streaming.vk.com", response['key'])

api.del_all_rules()
api.add_rules(f"rule_1", "квартира снимать комната спб")
api.add_rules(f"rule_2", "квартира сдавать комната спб")
api.add_rules(f"rule_3", "квартира сдам комната спб")

print("currently", len(api.get_rules()), "rules loaded")


@api.stream
def my_func(event):
    event_text = event['text']
    if "attachments" in event:
        # img_links = [item['photo_link'] for item in event['attachments']]
        s = process_text_vk(event_text)
        if s and check_duplicates(s):
            print("adding new event")
            post_id = db.flats.insert_one({
                "text": s,
                "link": event['event_url'],
                "from": "vk_streaming",
                "sent": False,