예제 #1
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()
예제 #2
0
# -*- coding: utf-8 -*-
from vkstreaming import Streaming

if __name__ == '__main__':
    api = Streaming("streaming.vk.com", "<key>")

    api.del_all_rules()
    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()
예제 #3
0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from vkstreaming import Streaming
import postgresql
db = postgresql.open('pq://<dbuser>:<dbpassword>@localhost:5432/<dbname>')
ins = db.prepare(
    "INSERT INTO stream (is_post, user_id,post_id,tags,text,creation_time) VALUES ($1, $2, $3, $4, $5, $6)"
)

if __name__ == '__main__':
    api = Streaming("streaming.vk.com", "<VKStreamAPIToken>")

    api.del_all_rules()
    api.add_rules("K", "хорошо")
    #api.add_rules("B1", "навальный")
    #api.add_rules("B2", "приболел")
    #api.add_rules("B3", "грипп")
    #api.add_rules("B4", "простуда")
    #api.add_rules("B5", "выздоравливай")

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

    @api.stream
    def my_func(event):
        if int(event['author']['id']) > 0:
            if event['event_type'] != 'share':
                if len(event['text']) < 500:
                    print("{} [{}|{}]: {} : {}".format(
                        event['event_type'], event['author']['id'],
예제 #4
0
파일: pars.py 프로젝트: AndrewRyaguzov/mega
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(
                vk.users.get(user_ids=author['id'], fields='verified'))
예제 #5
0
#!/usr/bin/env python
# -*- 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",