當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。