示例#1
0
def connect2stream():
    logging.info("trying to connect to stream")

    for i in range(MAX_CONNECT_TRIES):
        response = getServerUrl(config['vk']['secure_key'])
        try:
            api = Streaming(response["endpoint"], response["key"])
        except VkError as e:
            logging.error("Error [{}] while connectiong to stream: {}".format(
                e.error_code, e.message))
            time.sleep(CONNECT_ERR_SLEEP)
        break

    return api
示例#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()
示例#3
0
import json
import datetime
from agents_platform import settings
# from handler import vk_handler
from services import utils
from vkstreaming import Streaming

# vk_subscriptions = settings.vk_subscriptions
api = Streaming("streaming.vk.com", settings.VK_KEY)
last_time = datetime.datetime.now() + datetime.timedelta(minutes=5)
data = []


@api.stream
def my_func(event):
    handle_result(event)
    return


@utils.postpone
def handle_result(event):
    print(json.dumps(event, indent=4, sort_keys=True, ensure_ascii=False))
    vk_subscriptions = utils.read_data('vk_subscriptions.json')
    if event['event_type'] == 'post':
        for tag in event['tags']:
            if tag in vk_subscriptions:
                global last_time
                if datetime.datetime.now() - last_time <= datetime.timedelta(
                        seconds=5):
                    data.append(event)
                else:
示例#4
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()
示例#5
0
import vk_api
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":
示例#6
0
# -*- coding: utf-8 -*-
from vkstreaming import Streaming

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

    list = [{
        "tag": "Биткоин",
        "value": 'биткоин'
    }, {
        "tag": "BTC",
        "value": 'btc'
    }, {
        "tag": "ETH",
        "value": 'eth'
    }, {
        "tag": "NEM",
        "value": 'nem'
    }]
    api.update_rules(list)

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

    @api.stream
    def my_func(event):
        print("[{}]:[{}] {}".format(event['tags'], event['event_type'],
                                    event['event_url']))

示例#7
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'],
#!/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",