def create_sessions(tokens):
    for token in tokens:
        session = Session(access_token=tokens[token])
        vk_api = API(session)
        tokens[token] = vk_api
    print('All sessions created successfully.')
    return tokens
Ejemplo n.º 2
0
def vk_info(id, token):
    session = Session(access_token=token)
    vk_api = API(session)
    result = vk_api.users.get(user_ids=[0], fields=['photo_200'])[0]

    result['image_url'] = result['photo_200']

    return result
Ejemplo n.º 3
0
 def __init__(self, owner_id, api=None, start_iteration=0):
     if not api:
         from vk import Session, API
         self.api = API(Session())
     else:
         self.api = api
     self.owner_id = owner_id
     self.iteration = start_iteration
Ejemplo n.º 4
0
def auth_vk():
    try:
        session = Session()
        api = API(session)
    except Exception as e:
        print('vk not authed\n', e)

    return api
Ejemplo n.º 5
0
def get_friend_list(user_id):
    session = Session(
        access_token=
        "43cceeb8506f5e63619914ac18aee451be826d70ea833e646fcf22440730aeb27ac8a865b0bfde7a0e776"
    )
    vk_api = API(session, v="5.103")
    user = vk_api.users.get(user_id=280945440)
    # vk_session = VkApi("+375293164565", "1ron13branch37")
    # vk_session.auth()
    # api = vk_session.get_api()
    # print(api)
    print(user)
    return []
Ejemplo n.º 6
0
    def dispatch(self, request, *args, **kwargs):
        token = request.user.social_auth.get(
            provider='vk-oauth2').extra_data['access_token']
        self.api = API(Session(), access_token=token)
        groups = self.api.groups.get(filter='editor',
                                     extended=True,
                                     fields='is_closed')[1:]
        self.groups = [(
            None,
            '---------',
        )] + [(
            str(group['gid']),
            group['name'],
        ) for group in groups if group['is_closed'] < 2]

        return super(CreateEventView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     print(self.request.POST)
     form = VkImageUploaderForm(data=self.request.POST)
     print(form)
     if form.is_valid():
         token = request.user.social_auth.get(
             provider='vk-oauth2').extra_data['access_token']
         print(token)
         api = API(Session(), access_token=token)
         path = form.cleaned_data.get('img')
         print(path)
         upload_url = form.cleaned_data.get('upload_url')
         #r = requests.post(upload_url, files={'file1': open(path, 'rb')})
         r = requests.post("http://127.0.0.1:8080/",
                           files={'file1': open(path, 'rb')})
         return HttpResponse(r.text, content_type="text/plain", status=200)
     return HttpResponse('kek', content_type="text/plain", status=500)
Ejemplo n.º 8
0
    def __init__(self, token):
        self.token = token

        self.session = Session(access_token=self.token)
        self.api = API(self.session)
Ejemplo n.º 9
0
from vk import API, Session
from functools import reduce
from json import load, dump

with open('result.json', 'w') as result:
    dump(
        list((lambda api, groups: set.intersection(*map(
            lambda g: set(
                reduce(
                    lambda a, o: a + api.groups.getMembers(group_id=g,
                                                           offset=o)['users'],
                    range(0,
                          api.groups.getMembers(group_id=g)['count'], 1000), [
                          ])), groups)))(API(Session()),
                                         load(open('groups.json')))), result)
Ejemplo n.º 10
0
def name_to_id(token_0, long_name_0):
    session = Session(access_token=token_0)
    vk_api = API(session)
    information = vk_api.utils.resolveScreenName(screen_name=long_name_0,
                                                 v=5.80)
    return information
def create_session(token):
    session = Session(access_token=token)
    vk_api = API(session)
    return vk_api
Ejemplo n.º 12
0
 def __init__(self, access_token: str):
     self.__access_token = access_token
     self.__session = Session(self.__access_token)
Ejemplo n.º 13
0
from vk import Session, API
from __main__ import myprint, vk_request
import target

#uid -> obj
from pickle import load
try:
    utokens = load(open('vectors', 'rb'))
except:
    utokens = []
vectors = dict()
if utokens:
    for token, uid in utokens:
        vectors[uid] = API(Session(access_token=token))

import methods


def flist():
    print('Доступные:')
    i = 1
    for uid, obj in vectors.items():
        print('{:>2}. {} ({})'.format(i, methods.names(uid, obj), uid))
        i += 1
    print('Установленные:')
    i = 1
    for uid, info in target.vectors.items():
        print('{:>2}. {} -> {} ({} ур.)'.format(i, info[0], uid, info[1]))
        i += 1