mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Merge pull request #10 from codeofdusk/next-gen
Sounds tutorial refactor and docstring cleanup
This commit is contained in:
commit
c45a208cd6
11
src/extra/SoundsTutorial/reverse_sort.py
Normal file
11
src/extra/SoundsTutorial/reverse_sort.py
Normal file
@ -0,0 +1,11 @@
|
||||
#Reverse sort, by Bill Dengler <codeofdusk@gmail.com> for use in TWBlue http://twblue.es
|
||||
def invert_tuples(t):
|
||||
"Invert a list of tuples, so that the 0th element becomes the -1th, and the -1th becomes the 0th."
|
||||
res=[]
|
||||
for i in t:
|
||||
res.append(i[::-1])
|
||||
return res
|
||||
|
||||
def reverse_sort(t):
|
||||
"Sorts a list of tuples/lists by their last elements, not their first."
|
||||
return invert_tuples(sorted(invert_tuples(t)))
|
@ -4,6 +4,7 @@ import widgetUtils
|
||||
import os
|
||||
import paths
|
||||
import logging
|
||||
import reverse_sort
|
||||
log = logging.getLogger("extra.SoundsTutorial.soundsTutorial")
|
||||
import soundsTutorial_constants
|
||||
if platform.system() == "Windows":
|
||||
@ -22,6 +23,8 @@ class soundsTutorial(object):
|
||||
self.files = []
|
||||
log.debug("Searching sound files...")
|
||||
[self.files.append(i[0]) for i in soundsTutorial_constants.actions]
|
||||
log.debug("Alphabetizing actions...")
|
||||
actions=reverse_sort.reverse_sort(actions)
|
||||
log.debug("Creating dialog...")
|
||||
self.dialog = UI.soundsTutorialDialog(self.actions)
|
||||
widgetUtils.connect_event(self.dialog.play, widgetUtils.BUTTON_PRESSED, self.on_play)
|
||||
|
@ -1,25 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
actions = [ ("audio", _(u"The tweet may contain a playable audio")),
|
||||
("create_timeline", _(u"A timeline has been created")),
|
||||
("delete_timeline", _(u"A timeline has been deleted")),
|
||||
("dm_received", _(u"You've received a direct message")),
|
||||
("dm_sent", _(u"You've sent a direct message")),
|
||||
("error", _(u"A bug has happened")),
|
||||
("favourite", _(u"You've added a tweet to your favourites")),
|
||||
("favourites_timeline_updated", _(u"Someone's favourites have been updated")),
|
||||
("geo", _(u"The tweet has coordinates to determine its location")),
|
||||
("limit", _(u"There are no more tweets to read")),
|
||||
("list_tweet", _(u"A list has a new tweet")),
|
||||
("max_length", _(u"You can't add any more characters on the tweet")),
|
||||
("mention_received", _(u"You've been mentioned ")),
|
||||
("new_event", _(u"A new event has happened")),
|
||||
("ready", _(u"TW Blue is ready ")),
|
||||
("reply_send", _(u"You've replied")),
|
||||
("retweet_send", _(u"You've retweeted")),
|
||||
("search_updated", _(u"A search has been updated")),
|
||||
("tweet_received", _(u"There's a new tweet in the main buffer")),
|
||||
("tweet_send", _(u"You've sent a tweet")),
|
||||
("trends_updated", _(u"A trending topic buffer has been updated")),
|
||||
("tweet_timeline", _(u"There's a new tweet in a timeline")),
|
||||
("update_followers", _(u"You have a new follower")),
|
||||
("volume_changed", _(u"You've turned the volume up or down"))]
|
||||
actions = [ ("audio", _(u"Audio tweet.")),
|
||||
("create_timeline", _(u"User-defined buffer created.")),
|
||||
("delete_timeline", _(u"User-defined buffer destroied.")),
|
||||
("dm_received", _(u"Direct message received.")),
|
||||
("dm_sent", _(u"Direct message sent.")),
|
||||
("error", _(u"Error.")),
|
||||
("favourite", _(u"You favorited a tweet.")),
|
||||
("favourites_timeline_updated", _(u"Someone's favourites have been updated.")),
|
||||
("geo", _(u"Geotweet.")),
|
||||
("limit", _(u"Boundary reached.")),
|
||||
("list_tweet", _(u"List updated.")),
|
||||
("max_length", _(u"Too many characters.")),
|
||||
("mention_received", _(u"You've been mentioned.")),
|
||||
("new_event", _(u"New event.")),
|
||||
("ready", _(u"Application is ready.")),
|
||||
("reply_send", _(u"You've replied publicly.")),
|
||||
("retweet_send", _(u"You've retweeted.")),
|
||||
("search_updated", _(u"A search buffer has been updated.")),
|
||||
("tweet_received", _(u"New tweet in home buffer.")),
|
||||
("tweet_send", _(u"You've sent a tweet.")),
|
||||
("trends_updated", _(u"A trending topic buffer has been updated.")),
|
||||
("tweet_timeline", _(u"New tweet in user-defined buffer.")),
|
||||
("update_followers", _(u"New follower.")),
|
||||
("volume_changed", _(u"Volume changed."))]
|
@ -25,14 +25,14 @@ class Session(object):
|
||||
|
||||
def _require_login(fn):
|
||||
|
||||
""" Decorator for checking if the user is logged (a twitter object has credentials) on twitter.
|
||||
Some functions may need this to avoid make unneeded twitter API calls."""
|
||||
""" Decorator for checking if the user is logged in(a twitter object has credentials) on twitter.
|
||||
Some functions may need this to avoid making unneeded twitter API calls."""
|
||||
|
||||
def f(self, *args, **kwargs):
|
||||
if self.logged == True:
|
||||
fn(self, *args, **kwargs)
|
||||
else:
|
||||
raise Exceptions.NotLoggedSessionError("You are not logged yet.")
|
||||
raise Exceptions.NotLoggedSessionError("You are not logged in yet.")
|
||||
return f
|
||||
|
||||
def _require_configuration(fn):
|
||||
@ -48,10 +48,10 @@ class Session(object):
|
||||
|
||||
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.
|
||||
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
|
||||
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)
|
||||
name str: The name for the buffer stored in the dictionary.
|
||||
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
|
||||
if self.db.has_key(name) == False:
|
||||
@ -118,7 +118,7 @@ class Session(object):
|
||||
@_require_configuration
|
||||
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 self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
|
||||
@ -134,7 +134,7 @@ class Session(object):
|
||||
@_require_configuration
|
||||
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:
|
||||
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):
|
||||
|
||||
""" 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.
|
||||
If twitter returns an error, it will not call anymore the method.
|
||||
""" 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 the method anymore.
|
||||
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".
|
||||
_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.
|
||||
preexec_message str: A message to speak to the user while the call is doing the work, example: "try to follow to x user"."""
|
||||
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 method is running, example: "trying to follow x user"."""
|
||||
|
||||
finished = False
|
||||
tries = 0
|
||||
@ -193,8 +193,8 @@ class Session(object):
|
||||
@_require_login
|
||||
def get_favourites_timeline(self, name, *args, **kwargs):
|
||||
|
||||
""" Gets favourites for the authenticated user or a friend or follower or somewhat.
|
||||
name str: Name for store all in the database."""
|
||||
""" Gets favourites for the authenticated user or a friend or follower.
|
||||
name str: Name for storage in the database."""
|
||||
|
||||
tl = self.call_paged(self.twitter.twitter.get_favorites, *args, **kwargs)
|
||||
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.
|
||||
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
|
||||
return a list with all items retrieved."""
|
||||
returns a list with all items retrieved."""
|
||||
|
||||
max = int(self.settings["general"]["max_api_calls"])-1
|
||||
results = []
|
||||
@ -222,7 +222,6 @@ class Session(object):
|
||||
def get_user_info(self):
|
||||
|
||||
""" Retrieves some information required by TWBlue for setup."""
|
||||
|
||||
f = self.twitter.twitter.get_account_settings()
|
||||
sn = f["screen_name"]
|
||||
self.settings["twitter"]["user_name"] = sn
|
||||
@ -239,7 +238,7 @@ class Session(object):
|
||||
@_require_login
|
||||
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)
|
||||
|
||||
@ -254,7 +253,7 @@ class Session(object):
|
||||
def get_stream(self, name, function, *args, **kwargs):
|
||||
|
||||
""" 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."""
|
||||
|
||||
last_id = -1
|
||||
@ -272,11 +271,11 @@ class Session(object):
|
||||
@_require_login
|
||||
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.
|
||||
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.
|
||||
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_ = []
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user