当前位置: 首页>>代码示例>>Python>>正文


Python vk.API属性代码示例

本文整理汇总了Python中vk.API属性的典型用法代码示例。如果您正苦于以下问题:Python vk.API属性的具体用法?Python vk.API怎么用?Python vk.API使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在vk的用法示例。


在下文中一共展示了vk.API属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getMusicList

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def getMusicList(login, password, isInvisible):
    """
    login: str;
    password: str;
    isInvisible: boolean, True if set invisible user else False;
    return dict.
    """
    
    if not checkConnection():
        return {}

    session = vk.AuthSession(app_id='5566502', user_login=login,
                             user_password=password, scope='audio')
    api = vk.API(session)

    if isInvisible: 
        api.account.setOffline()

    musics = api.audio.get() or {}
    try:
        return {'%s - %s' % (s['artist'], s['title']): s['url'] for s in musics}
    except Exception as exception:
        raise exception
        return {} 
开发者ID:akanoi,项目名称:download-music-vk,代码行数:26,代码来源:authorization.py

示例2: search_users

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def search_users(message, text):
    session = VkMessage(vk_tokens.get(str(message.from_user.id))).session
    markup = types.InlineKeyboardMarkup(row_width=1)
    result = vk.API(session).messages.searchDialogs(q=text, limit=10, fields=[])
    for chat in result:
        if chat['type'] == 'profile':
            markup.add(types.InlineKeyboardButton('{} {}'.format(chat['first_name'], chat['last_name']),
                                                  callback_data=str(chat['uid'])))
        elif chat['type'] == 'chat':
            markup.add(
                types.InlineKeyboardButton(replace_shields(chat['title']),
                                           callback_data='group' + str(chat['chat_id'])))
    if markup.keyboard:
        markup.add(types.InlineKeyboardButton('????? ??', callback_data='search'))
        bot.send_message(message.from_user.id, '<b>????????? ?????? ??</b> <i>{}</i>'.format(text),
                         reply_markup=markup, parse_mode='HTML')
    else:
        markup.add(types.InlineKeyboardButton('????? ??', callback_data='search'))
        bot.send_message(message.from_user.id, '<b>?????? ?? ??????? ?? ???????</b> <i>{}</i>'.format(text),
                         parse_mode='HTML', reply_markup=markup) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:22,代码来源:bot.py

示例3: setUp

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def setUp(self):
        auth_session = vk.AuthSession(app_id=APP_ID, user_login=USER_LOGIN, user_password=USER_PASSWORD)
        access_token, _ = auth_session.get_access_token()

        session = vk.Session(access_token=access_token)
        self.vk_api = vk.API(session, lang='ru') 
开发者ID:it2school,项目名称:Projects,代码行数:8,代码来源:tests.py

示例4: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def __init__(self, app_id, username = None, password = None, access_token = None, scope = ''):
        if access_token:
            session = vk.api.Session(access_token = access_token)
        else:
            session = vk.api.AuthSession(app_id, username, password, scope = scope)
        self.conn = vk.API(session)
        self.last_request = 0.0 
开发者ID:inpos,项目名称:kodi-vk.inpos.ru,代码行数:9,代码来源:default.py

示例5: auth_vk

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def auth_vk():
	try:
		session = Session()
		api = API(session)
	except Exception as e:
		print('vk not authed\n', e)

	return api 
开发者ID:murych,项目名称:slack-vk-bot,代码行数:10,代码来源:auth.py

示例6: verifycode

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def verifycode(code):
    session = vk.Session(access_token=code)
    api = vk.API(session)
    return dict(api.account.getProfileInfo(fields=[])) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:6,代码来源:bot.py

示例7: send_video

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def send_video(message, userid, group, forward_messages=None):
    filetype = message.content_type
    session = VkMessage(vk_tokens.get(str(message.from_user.id))).session

    file = wget.download(
        FILE_URL.format(token, bot.get_file(getattr(message, filetype).file_id).wait().file_path))
    openedfile = open(file, 'rb')
    files = {'video_file': openedfile}

    if group:
        attachment = vk.API(session).video.save(is_private=1)
        fileonserver = ujson.loads(requests.post(attachment['upload_url'],
                                                 files=files).text)
        video = 'video{}_{}'.format(attachment['owner_id'], attachment['owner_id']['video_id'])
        if message.caption:
            vk.API(session).messages.send(chat_id=userid, message=message.caption, attachment=video,
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(chat_id=userid, attachment=video, forward_messages=forward_messages)
    else:
        attachment = vk.API(session).video.save(is_private=1)
        fileonserver = ujson.loads(requests.post(attachment['upload_url'],
                                                 files=files).text)
        video = 'video{}_{}'.format(attachment['owner_id'], attachment['vid'])
        if message.caption:
            vk.API(session).messages.send(user_id=userid, message=message.caption, attachment=video,
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(user_id=userid, attachment=video, forward_messages=forward_messages)
    openedfile.close()
    os.remove(file) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:33,代码来源:bot.py

示例8: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def __init__(self):
		user = DataUser()
		entered = False
		while True:
			if user.isHasData():
				data = user.getData()
				login = data[0]['login']
				if not entered:
					tempPas = input('Password (0 - log out): ')
					if tempPas == '0':
						self.log_out()
						continue
					elif user.checkPas(tempPas):
						pas = tempPas
						entered = True
					else:
						print('Invalid password. Try again')
						continue
				else:
					pas = tempPas
			else:
				print('Autorization')
				print('Enter your mail and password')
				login = input('Mail: ')
				pas = input('Password: ')
			try:
				session = vk.AuthSession(app_id=APP_ID, user_login=login, user_password=pas, scope='friends,photos,video')
				self._vk = vk.API(session)
				user.logIn(login, pas)
				break
			except VkAuthError:
				print('Invalid login or password, try again') 
开发者ID:Vladius95,项目名称:vk_downloader,代码行数:34,代码来源:vk_expansion.py

示例9: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def __init__(self, token):
        self.user = vk.API(access_token=token,session=vk.Session(),v=5.14) # ??? ??? ???????????, ?????? 5.14 ??? ????? ????
        self.last_call = time.time()
        self.calls = 0
        self.method = [] 
开发者ID:vaartis,项目名称:bots,代码行数:7,代码来源:dev_random.py

示例10: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def __init__(self, token):
        self.user = vk.API(access_token=token,session=vk.Session(),v=5.14)
        self.last_call = time.time()
        self.calls = 0
        self.method = [] 
开发者ID:vaartis,项目名称:bots,代码行数:7,代码来源:req.py

示例11: get_all_messages

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def get_all_messages(self):
        logger.debug("Retrieving messages")
        if self.testmode:
            msg = raw_input("msg>> ")
            msg = msg.decode('utf-8')
            messages = [{"read_state":0, "id":"0","body":msg,"chat_id":2}]
        else:
            code = """var k = 200;
var messages = API.messages.get({"count": k});

var ids = "";
var a = k;  
while (a >= 0) 
{ 
ids=ids+messages["items"][a]["id"]+",";
a = a-1;
}; 
ids = ids.substr(0,ids.length-1);
API.messages.markAsRead({"message_ids":ids});

return messages;"""
#            operation = self.api.messages.get
            operation = self.api.execute
            args = {"code" : code}
            ret = rated_operation( operation, args )
            messages = ret["items"]

        return messages
        #self.process_messages(messages) 
开发者ID:detorto,项目名称:tulen,代码行数:31,代码来源:vkuser.py

示例12: callback_buttons

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def callback_buttons(call):
    if call.message:
        if 'page' in call.data:
            try:
                create_markup(call.message, call.from_user.id, int(call.data.split('page')[1]), True)
            except:
                session = VkMessage(vk_tokens.get(str(call.from_user.id))).session
                request_user_dialogs(session, call.from_user.id)
                create_markup(call.message, call.from_user.id, int(call.data.split('page')[1]), True)
            bot.answer_callback_query(call.id).wait()
        elif 'search' in call.data:
            markup = types.ForceReply(selective=False)
            bot.answer_callback_query(call.id, '????? ?????? ??').wait()
            bot.send_message(call.from_user.id, '<b>????? ??????</b> ??',
                             parse_mode='HTML', reply_markup=markup).wait()
        elif 'group' in call.data:
            session = VkMessage(vk_tokens.get(str(call.from_user.id))).session
            chat = vk.API(session).messages.getChat(chat_id=call.data.split('group')[1], fields=[])
            bot.answer_callback_query(call.id,
                                      '?? ? ?????? {}'.format(replace_shields(chat['title']))).wait()
            bot.send_message(call.from_user.id,
                             '<i>?? ? ?????? {}</i>'.format(chat['title']),
                             parse_mode='HTML').wait()
            currentchat[str(call.from_user.id)] = {'title': chat['title'], 'id': 'group' + str(chat['chat_id'])}
        elif call.data.lstrip('-').isdigit():
            session = VkMessage(vk_tokens.get(str(call.from_user.id))).session
            if '-' in call.data:
                user = vk.API(session).groups.getById(group_id=call.data.lstrip('-'), fields=[])[0]
                user = {'first_name': user['name'], 'last_name': ''}
            else:
                user = vk.API(session).users.get(user_ids=call.data, fields=[])[0]
            bot.answer_callback_query(call.id,
                                      '?? ? ???? ? {} {}'.format(user['first_name'], user['last_name'])).wait()
            bot.send_message(call.from_user.id,
                             '<i>?? ? ???? ? {} {}</i>'.format(user['first_name'], user['last_name']),
                             parse_mode='HTML').wait()
            currentchat[str(call.from_user.id)] = {'title': user['first_name'] + ' ' + user['last_name'],
                                                   'id': call.data} 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:40,代码来源:bot.py

示例13: create_thread

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def create_thread(uid, vk_token):
    a = VkPolling()
    longpoller = VkMessage(vk_token)
    t = threading.Thread(name='vk' + str(uid), target=a.run, args=(longpoller, bot, uid,))
    t.setDaemon(True)
    t.start()
    vk_threads[str(uid)] = a
    vk_tokens.set(str(uid), vk_token)
    vk.API(longpoller.session).account.setOffline() 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:11,代码来源:bot.py

示例14: send_photo

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def send_photo(message, userid, group, forward_messages=None):
    filetype = message.content_type
    session = VkMessage(vk_tokens.get(str(message.from_user.id))).session
    file = wget.download(
        FILE_URL.format(token, bot.get_file(getattr(message, filetype)[-1].file_id).wait().file_path))
    openedfile = open(file, 'rb')
    files = {'file': openedfile}
    fileonserver = ujson.loads(requests.post(vk.API(session).photos.getMessagesUploadServer()['upload_url'],
                                             files=files).text)
    attachment = vk.API(session).photos.saveMessagesPhoto(server=fileonserver['server'], photo=fileonserver['photo'],
                                                          hash=fileonserver['hash'])
    if group:
        if message.caption:
            vk.API(session).messages.send(chat_id=userid, message=message.caption, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(chat_id=userid, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
    else:
        if message.caption:
            vk.API(session).messages.send(user_id=userid, message=message.caption, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(user_id=userid, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
    openedfile.close()
    os.remove(file) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:29,代码来源:bot.py

示例15: send_sticker

# 需要导入模块: import vk [as 别名]
# 或者: from vk import API [as 别名]
def send_sticker(message, userid, group, forward_messages=None):
    filetype = message.content_type
    session = VkMessage(vk_tokens.get(str(message.from_user.id))).session
    file = wget.download(
        FILE_URL.format(token, bot.get_file(getattr(message, filetype).file_id).wait().file_path))
    Image.open(file).save("{}.png".format(file))
    openedfile = open('{}.png'.format(file), 'rb')
    files = {'file': openedfile}
    fileonserver = ujson.loads(requests.post(vk.API(session).photos.getMessagesUploadServer()['upload_url'],
                                             files=files).text)
    attachment = vk.API(session).photos.saveMessagesPhoto(server=fileonserver['server'], photo=fileonserver['photo'],
                                                          hash=fileonserver['hash'])
    if group:
        if message.caption:
            vk.API(session).messages.send(chat_id=userid, message=message.caption, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(chat_id=userid, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
    else:
        if message.caption:
            vk.API(session).messages.send(user_id=userid, message=message.caption, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
        else:
            vk.API(session).messages.send(user_id=userid, attachment=attachment[0]['id'],
                                          forward_messages=forward_messages)
    openedfile.close()
    os.remove('{}.png'.format(file))
    os.remove(file) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:31,代码来源:bot.py


注:本文中的vk.API属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。