Added a few comments to session

This commit is contained in:
Manuel Cortez 2018-12-24 08:53:28 -06:00
parent b4adf42644
commit 27b6d068ed

View File

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" Session object for Socializer. A session is the only object to call VK API methods, save settings and access to the cache database and sound playback mechanisms. """
import os import os
import logging import logging
import languageHandler import languageHandler
import paths import paths
import vkSessionHandler import vkSessionHandler
import sound import sound
import core
from config_utils import Configuration, ConfigurationResetException from config_utils import Configuration, ConfigurationResetException
from pubsub import pub from pubsub import pub
from vk_api.exceptions import LoginRequired, VkApiError from vk_api.exceptions import LoginRequired, VkApiError
@ -14,7 +14,7 @@ log = logging.getLogger("session")
sessions = {} sessions = {}
# Saves possible set of identifier keys for VK'S data types # Save possible set of identifier keys for VK'S data types
# see https://vk.com/dev/datatypes for more information. # see https://vk.com/dev/datatypes for more information.
# I've added the Date identifier (this is a field in unix time format), for special objects (like friendship indicators) because these objects don't have an own identifier. # I've added the Date identifier (this is a field in unix time format), for special objects (like friendship indicators) because these objects don't have an own identifier.
identifiers = ["aid", "gid", "uid", "pid", "id", "post_id", "nid", "date"] identifiers = ["aid", "gid", "uid", "pid", "id", "post_id", "nid", "date"]
@ -23,8 +23,11 @@ identifiers = ["aid", "gid", "uid", "pid", "id", "post_id", "nid", "date"]
post_types = dict(audio="audio", friend="friends", video="video", post="post_type") post_types = dict(audio="audio", friend="friends", video="video", post="post_type")
def find_item(list, item): def find_item(list, item):
""" Finds an item in a list by taking an identifier""" """ Find an item in a list by taking an identifier.
# determines the kind of identifier that we are using @list list: A list of dict objects.
@ item dict: A dictionary containing at least an identifier.
"""
# determine the kind of identifier that we are using
global identifiers global identifiers
identifier = None identifier = None
for i in identifiers: for i in identifiers:
@ -40,12 +43,12 @@ def find_item(list, item):
return False return False
class vkSession(object): class vkSession(object):
""" The only session available in socializer. Manages everything related to a model in an MVC app: calls to VK, sound handling, settings and a cache database."""
def order_buffer(self, name, data, show_nextpage): def order_buffer(self, name, data, show_nextpage):
""" Put new items on the local cache database.
""" Put new items on the local database. Useful for cursored buffers @name str: The name for the buffer stored in the dictionary.
name str: The name for the buffer stored in the dictionary. @data list: A list with items and some information about cursors.
data list: A list with items and some information about cursors.
returns the number of items that has been added in this execution""" returns the number of items that has been added in this execution"""
global post_types global post_types
first_addition = False first_addition = False
@ -237,8 +240,3 @@ class vkSession(object):
log.debug("Getting user identifier...") log.debug("Getting user identifier...")
user = self.vk.client.users.get(fields="uid, first_name, last_name") user = self.vk.client.users.get(fields="uid, first_name, last_name")
self.user_id = user[0]["id"] self.user_id = user[0]["id"]
# receipt = core.getReceipt(str(self.user_id))
# print receipt
# token = core.validateToken(self.vk.session_object.token["access_token"], receipt)
# print token
# self.vk.session_object.token = dict(access_token=token)