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


Python vk.Session方法代码示例

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


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

示例1: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [as 别名]
def __init__(self, config):
        self.config = config

        self.session = vk.Session(access_token=self.config["bot"]['token'])
        self.vkapi = vkApiThrottle(self.session, v='5.58')
        self.bot_id = self.vkapi.users.get()[0]['id']
        self.scheduler = BackgroundScheduler()

        self.chat_queue = VkUpdates(self.vkapi)

        self.chatplugins = {}
        self.scheduleplugins = {}

        for plugin_name in self.config["bot"]['chatplugins']:
            plugin = importlib.import_module('chatplugins.' + plugin_name)
            self.chatplugins[plugin_name] = plugin.ChatPlugin(self)

        for plugin_name in self.config["bot"]['scheduleplugins']:
            plugin = importlib.import_module('scheduleplugins.' + plugin_name)
            self.scheduleplugins[plugin_name] = plugin.SchedulePlugin(self)

        for plugin_name, plugin in self.scheduleplugins.items():
            self.scheduler.add_job(plugin.call, id=plugin_name, trigger='interval', **plugin.interval) 
开发者ID:hdk5,项目名称:cosinus,代码行数:25,代码来源:bot.py

示例2: setUp

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [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

示例3: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [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

示例4: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [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

示例5: auth_vk

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [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 Session [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: get_session

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [as 别名]
def get_session(token):
    return vk.Session(access_token=token) 
开发者ID:Kylmakalle,项目名称:tgvkbot,代码行数:4,代码来源:vk_messages.py

示例8: download_wall

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [as 别名]
def download_wall(domain, dataset_folder, cut=1000000, access_token=None):
    import vk
    session = vk.Session(access_token=access_token)
    api = vk.API(session)
    info = dict()
    docs_folder = os.path.join(dataset_folder, "documents")
    os.makedirs(docs_folder, exist_ok=True)
    os.makedirs(os.path.join(dataset_folder, "meta"), exist_ok=True)

    id = 0
    offset = 0
    while True:
        posts = api.wall.get(domain=domain, offset=offset, count=100)
        for i in range(1, len(posts)):
            post = posts[i]
            text = post["text"].replace("<br>", "\n")
            if len(text) > 50:
                id += 1
                text_id = "%06d.txt" % id
                info[text_id] = dict()
                info[text_id]["url"] = "https://vk.com/" + domain + \
                    "?w=wall" + str(post["from_id"]) + "_" + str(post["id"])
                info[text_id]["time"] = post["date"]
                text_file_name = os.path.join(docs_folder, text_id)
                with open(text_file_name, "w", encoding='utf-8') as f:
                    f.write(text)
            if id == cut:
                break
        offset += 100
        # print (offset)
        if len(posts) != 101:
            break
        if id == cut:
            break

    with open(os.path.join(dataset_folder, "meta", "meta.json"), "wb") as f:
        f.write(json.dumps(info).encode("UTF-8")) 
开发者ID:bigartm,项目名称:visartm,代码行数:39,代码来源:vkloader.py

示例9: __init__

# 需要导入模块: import vk [as 别名]
# 或者: from vk import Session [as 别名]
def __init__(self, config, update_stat, testmode = False):
	random.seed(time.time())
        self.config = config

        self.update_stat_ = update_stat

        if testmode:
            session = None
            self.api = None
            logger.info("Running in test mode")
        else:
            session = vk.Session(access_token=self.config["access_token"]["value"])
            self.api = vk.API(session,  v='5.50', timeout = 10)
            logger.info("VK API created")

        capthca_api_key = self.config.get("twocaptcha_api_key", None)
        if capthca_api_key:
            init_2captcha(capthca_api_key)
            logger.info("2Captcha initialized. balance: {}".format(utils._2captcha_api.get_balance()))

        run_ratelimit_dispatcher();
        logger.info("Rate-limit dispatcher started");
        

        modules_list_file = self.config.get("enabled_modules_list", None)

        if not modules_list_file:
            mods = self.config.get("enabled_modules", None)
        else:
            mods = [l.strip() for l in open(modules_list_file).readlines()]

        mods = [m for m in mods if not m.startswith("#")]
        if not mods:
            raise RuntimeError("Can't find any module to load!")
        logger.info("Enabled modules: [{}]".format(",".join(mods)))
        
        self.load_modules(mods)

        self.thread_pool_modules = ThreadPool(int(config.get("mod_threads", 4)))
        
        self.message_queue_general = multiprocessing.Queue()
        self.message_queue_parallel = multiprocessing.Queue()

        
        self.mutex = multiprocessing.Lock()
        
        self.testmode = testmode
        self.message_processors_general = [ threading.Thread(target=self.process_message_general) for x in xrange(int(config.get("msg_threads", 4)))]
        self.message_processors_parallel = [ threading.Thread(target=self.process_message_parallel) for x in xrange(int(config.get("mod_threads", 4)))]
        for t in self.message_processors_general:
            t.start()
        for t in self.message_processors_parallel:
            t.start()
        
        logger.info("Multiprocessing intiated: "+str(self.thread_pool_modules) + " "+ str(self.thread_pool_modules)) 
开发者ID:detorto,项目名称:tulen,代码行数:57,代码来源:vkuser.py


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