mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Fixed docstrings.
This commit is contained in:
parent
21c6a999b4
commit
8d6d452dfb
@ -25,14 +25,14 @@ class Session(object):
|
|||||||
|
|
||||||
def _require_login(fn):
|
def _require_login(fn):
|
||||||
|
|
||||||
""" Decorator for checking if the user is logged (a twitter object has credentials) on twitter.
|
""" Decorator for checking if the user is logged in(a twitter object has credentials) on twitter.
|
||||||
Some functions may need this to avoid make unneeded twitter API calls."""
|
Some functions may need this to avoid making unneeded twitter API calls."""
|
||||||
|
|
||||||
def f(self, *args, **kwargs):
|
def f(self, *args, **kwargs):
|
||||||
if self.logged == True:
|
if self.logged == True:
|
||||||
fn(self, *args, **kwargs)
|
fn(self, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise Exceptions.NotLoggedSessionError("You are not logged yet.")
|
raise Exceptions.NotLoggedSessionError("You are not logged in yet.")
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def _require_configuration(fn):
|
def _require_configuration(fn):
|
||||||
@ -48,10 +48,10 @@ class Session(object):
|
|||||||
|
|
||||||
def order_buffer(self, name, data):
|
def order_buffer(self, name, data):
|
||||||
|
|
||||||
""" Put the new items on the local database.
|
""" Put the new items in the local database.
|
||||||
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 tweets.
|
data list: A list with tweets.
|
||||||
returns the number of items that has been added in this execution"""
|
returns the number of items that have been added in this execution"""
|
||||||
|
|
||||||
num = 0
|
num = 0
|
||||||
if self.db.has_key(name) == False:
|
if self.db.has_key(name) == False:
|
||||||
@ -68,7 +68,7 @@ class Session(object):
|
|||||||
""" Put the new items on the local database. Useful for cursored buffers (followers, friends, users of a list and searches)
|
""" Put the new items on the local database. Useful for cursored buffers (followers, friends, users of a list and searches)
|
||||||
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 have been added in this execution"""
|
||||||
|
|
||||||
num = 0
|
num = 0
|
||||||
if self.db.has_key(name) == False:
|
if self.db.has_key(name) == False:
|
||||||
@ -118,7 +118,7 @@ class Session(object):
|
|||||||
@_require_configuration
|
@_require_configuration
|
||||||
def login(self, verify_credentials=True):
|
def login(self, verify_credentials=True):
|
||||||
|
|
||||||
""" Login in to twitter using credentials from settings.
|
""" Log into twitter using credentials from settings.
|
||||||
if the user account isn't authorised, it needs to call self.authorise() before login."""
|
if the user account isn't authorised, it needs to call self.authorise() before login."""
|
||||||
|
|
||||||
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
|
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
|
||||||
@ -134,7 +134,7 @@ class Session(object):
|
|||||||
@_require_configuration
|
@_require_configuration
|
||||||
def authorise(self):
|
def authorise(self):
|
||||||
|
|
||||||
""" Authorises a Twitter account. This function needs to be called for each new session, after of self.get_configuration() and before of self.login()"""
|
""" Authorises a Twitter account. This function needs to be called for each new session, after self.get_configuration() and before self.login()"""
|
||||||
|
|
||||||
if self.logged == True:
|
if self.logged == True:
|
||||||
raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.")
|
raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.")
|
||||||
@ -153,14 +153,14 @@ class Session(object):
|
|||||||
|
|
||||||
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
||||||
|
|
||||||
""" Make a call to the Twitter API. If there is a connectionError or another exception not related to Twitter, It will call to the method at least 25 times, waiting a while between calls. Useful for post methods.
|
""" Make a call to the Twitter API. If there is a connectionError or another exception not related to Twitter, It will call the method again at least 25 times, waiting a while between calls. Useful for post methods.
|
||||||
If twitter returns an error, it will not call anymore the method.
|
If twitter returns an error, it will not call the method anymore.
|
||||||
call_name str: The method to call
|
call_name str: The method to call
|
||||||
action str: The thing what you are doing on twitter, it will be reported to the user if report_success is set to True.
|
action str: What you are doing on twitter, it will be reported to the user if report_success is set to True.
|
||||||
for example "following @tw_blue2" will be reported as "following @tw_blue2 succeeded".
|
for example "following @tw_blue2" will be reported as "following @tw_blue2 succeeded".
|
||||||
_sound str: a sound to play if the call is executed properly.
|
_sound str: a sound to play if the call is executed properly.
|
||||||
report_success and report_failure bool: These are self explanatory. True or false. It's all.
|
report_success and report_failure bool: These are self explanatory. True or False.
|
||||||
preexec_message str: A message to speak to the user while the call is doing the work, example: "try to follow to x user"."""
|
preexec_message str: A message to speak to the user while the method is running, example: "trying to follow x user"."""
|
||||||
|
|
||||||
finished = False
|
finished = False
|
||||||
tries = 0
|
tries = 0
|
||||||
@ -193,8 +193,8 @@ class Session(object):
|
|||||||
@_require_login
|
@_require_login
|
||||||
def get_favourites_timeline(self, name, *args, **kwargs):
|
def get_favourites_timeline(self, name, *args, **kwargs):
|
||||||
|
|
||||||
""" Gets favourites for the authenticated user or a friend or follower or somewhat.
|
""" Gets favourites for the authenticated user or a friend or follower.
|
||||||
name str: Name for store all in the database."""
|
name str: Name for storage in the database."""
|
||||||
|
|
||||||
tl = self.call_paged(self.twitter.twitter.get_favorites, *args, **kwargs)
|
tl = self.call_paged(self.twitter.twitter.get_favorites, *args, **kwargs)
|
||||||
return self.order_buffer(name, tl)
|
return self.order_buffer(name, tl)
|
||||||
@ -204,7 +204,7 @@ class Session(object):
|
|||||||
""" Makes a call to the Twitter API methods several times. Useful for get methods.
|
""" Makes a call to the Twitter API methods several times. Useful for get methods.
|
||||||
this function is needed for retrieving more than 200 items.
|
this function is needed for retrieving more than 200 items.
|
||||||
update_function str: The function to call. This function must be child of self.twitter.twitter
|
update_function str: The function to call. This function must be child of self.twitter.twitter
|
||||||
return a list with all items retrieved."""
|
returns a list with all items retrieved."""
|
||||||
|
|
||||||
max = int(self.settings["general"]["max_api_calls"])-1
|
max = int(self.settings["general"]["max_api_calls"])-1
|
||||||
results = []
|
results = []
|
||||||
@ -222,7 +222,6 @@ class Session(object):
|
|||||||
def get_user_info(self):
|
def get_user_info(self):
|
||||||
|
|
||||||
""" Retrieves some information required by TWBlue for setup."""
|
""" Retrieves some information required by TWBlue for setup."""
|
||||||
|
|
||||||
f = self.twitter.twitter.get_account_settings()
|
f = self.twitter.twitter.get_account_settings()
|
||||||
sn = f["screen_name"]
|
sn = f["screen_name"]
|
||||||
self.settings["twitter"]["user_name"] = sn
|
self.settings["twitter"]["user_name"] = sn
|
||||||
@ -239,7 +238,7 @@ class Session(object):
|
|||||||
@_require_login
|
@_require_login
|
||||||
def get_lists(self):
|
def get_lists(self):
|
||||||
|
|
||||||
""" Gets the lists that the user is suscribed."""
|
""" Gets the lists that the user is subscribed to and stores them in the database. Returns None."""
|
||||||
|
|
||||||
self.db["lists"] = self.twitter.twitter.show_lists(reverse=True)
|
self.db["lists"] = self.twitter.twitter.show_lists(reverse=True)
|
||||||
|
|
||||||
@ -254,7 +253,7 @@ class Session(object):
|
|||||||
def get_stream(self, name, function, *args, **kwargs):
|
def get_stream(self, name, function, *args, **kwargs):
|
||||||
|
|
||||||
""" Retrieves the items for a regular stream.
|
""" Retrieves the items for a regular stream.
|
||||||
name str: Name to save items on the database.
|
name str: Name to save items to the database.
|
||||||
function str: A function to get the items."""
|
function str: A function to get the items."""
|
||||||
|
|
||||||
last_id = -1
|
last_id = -1
|
||||||
@ -272,11 +271,11 @@ class Session(object):
|
|||||||
@_require_login
|
@_require_login
|
||||||
def get_cursored_stream(self, name, function, items="users", *args, **kwargs):
|
def get_cursored_stream(self, name, function, items="users", *args, **kwargs):
|
||||||
|
|
||||||
""" Gets items for API calls that requires using cursors to paginate the results.
|
""" Gets items for API calls that require using cursors to paginate the results.
|
||||||
name str: Name to save it in the database.
|
name str: Name to save it in the database.
|
||||||
function str: Function that provides the items.
|
function str: Function that provides the items.
|
||||||
items: When the function returns the list with results, items will tell how the order function should be look.
|
items: When the function returns the list with results, items will tell how the order function should be look.
|
||||||
for example get_followers_list returns a list and users are under list["users"], here the items should be point to "users"."""
|
for example get_followers_list returns a list and users are under list["users"], here the items should point to "users"."""
|
||||||
|
|
||||||
items_ = []
|
items_ = []
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user