mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-01-31 13:20:45 -06:00
Implemented list creation, edition and removal
This commit is contained in:
parent
f546543e9b
commit
4643301764
@ -1,13 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
|
||||||
from builtins import object
|
|
||||||
import widgetUtils
|
import widgetUtils
|
||||||
import output
|
import output
|
||||||
|
import logging
|
||||||
from wxUI.dialogs import lists
|
from wxUI.dialogs import lists
|
||||||
from twython import TwythonError
|
from tweepy.error import TweepError
|
||||||
from sessions.twitter import compose, utils
|
from sessions.twitter import compose, utils
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
|
|
||||||
|
log = logging.getLogger("controller.listsController")
|
||||||
|
|
||||||
class listsController(object):
|
class listsController(object):
|
||||||
def __init__(self, session, user=None):
|
def __init__(self, session, user=None):
|
||||||
super(listsController, self).__init__()
|
super(listsController, self).__init__()
|
||||||
@ -31,7 +32,7 @@ class listsController(object):
|
|||||||
return [compose.compose_list(item) for item in self.session.db["lists"]]
|
return [compose.compose_list(item) for item in self.session.db["lists"]]
|
||||||
|
|
||||||
def get_user_lists(self, user):
|
def get_user_lists(self, user):
|
||||||
self.lists = self.session.twitter.show_lists(reverse=True, screen_name=user)
|
self.lists = self.session.twitter.lists_all(reverse=True, screen_name=user)
|
||||||
return [compose.compose_list(item) for item in self.lists]
|
return [compose.compose_list(item) for item in self.lists]
|
||||||
|
|
||||||
def create_list(self, *args, **kwargs):
|
def create_list(self, *args, **kwargs):
|
||||||
@ -48,8 +49,9 @@ class listsController(object):
|
|||||||
new_list = self.session.twitter.create_list(name=name, description=description, mode=mode)
|
new_list = self.session.twitter.create_list(name=name, description=description, mode=mode)
|
||||||
self.session.db["lists"].append(new_list)
|
self.session.db["lists"].append(new_list)
|
||||||
self.dialog.lista.insert_item(False, *compose.compose_list(new_list))
|
self.dialog.lista.insert_item(False, *compose.compose_list(new_list))
|
||||||
except TwythonError as e:
|
except TweepError as e:
|
||||||
output.speak("error %s: %s" % (e.status_code, e.msg))
|
output.speak("error %s: %s" % (e.api_code, e.reason))
|
||||||
|
log.exception("error %s: %s" % (e.api_code, e.reason))
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def edit_list(self, *args, **kwargs):
|
def edit_list(self, *args, **kwargs):
|
||||||
@ -65,44 +67,44 @@ class listsController(object):
|
|||||||
else:
|
else:
|
||||||
mode = "private"
|
mode = "private"
|
||||||
try:
|
try:
|
||||||
self.session.twitter.update_list(list_id=list["id"], name=name, description=description, mode=mode)
|
self.session.twitter.update_list(list_id=list.id, name=name, description=description, mode=mode)
|
||||||
self.session.get_lists()
|
self.session.get_lists()
|
||||||
self.dialog.populate_list(self.get_all_lists(), True)
|
self.dialog.populate_list(self.get_all_lists(), True)
|
||||||
except TwythonError as e:
|
except TweepError as e:
|
||||||
output.speak("error %s: %s" % (e.error_code, e.msg))
|
output.speak("error %s: %s" % (e.api_code, e.reason))
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def remove_list(self, *args, **kwargs):
|
def remove_list(self, *args, **kwargs):
|
||||||
if self.dialog.lista.get_count() == 0: return
|
if self.dialog.lista.get_count() == 0: return
|
||||||
list = self.session.db["lists"][self.dialog.get_item()]["id"]
|
list = self.session.db["lists"][self.dialog.get_item()].id
|
||||||
if lists.remove_list() == widgetUtils.YES:
|
if lists.remove_list() == widgetUtils.YES:
|
||||||
try:
|
try:
|
||||||
self.session.twitter.delete_list(list_id=list)
|
self.session.twitter.destroy_list(list_id=list)
|
||||||
self.session.db["lists"].pop(self.dialog.get_item())
|
self.session.db["lists"].pop(self.dialog.get_item())
|
||||||
self.dialog.lista.remove_item(self.dialog.get_item())
|
self.dialog.lista.remove_item(self.dialog.get_item())
|
||||||
except TwythonError as e:
|
except TweepError as e:
|
||||||
output.speak("error %s: %s" % (e.error_code, e.msg))
|
output.speak("error %s: %s" % (e.api_code, e.reason))
|
||||||
|
|
||||||
def open_list_as_buffer(self, *args, **kwargs):
|
def open_list_as_buffer(self, *args, **kwargs):
|
||||||
if self.dialog.lista.get_count() == 0: return
|
if self.dialog.lista.get_count() == 0: return
|
||||||
list = self.session.db["lists"][self.dialog.get_item()]
|
list = self.session.db["lists"][self.dialog.get_item()]
|
||||||
pub.sendMessage("create-new-buffer", buffer="list", account=self.session.db["user_name"], create=list["name"])
|
pub.sendMessage("create-new-buffer", buffer="list", account=self.session.db["user_name"], create=list.name)
|
||||||
|
|
||||||
def subscribe(self, *args, **kwargs):
|
def subscribe(self, *args, **kwargs):
|
||||||
if self.dialog.lista.get_count() == 0: return
|
if self.dialog.lista.get_count() == 0: return
|
||||||
list_id = self.lists[self.dialog.get_item()]["id"]
|
list_id = self.lists[self.dialog.get_item()].id
|
||||||
try:
|
try:
|
||||||
list = self.session.twitter.subscribe_to_list(list_id=list_id)
|
list = self.session.twitter.subscribe_list(list_id=list_id)
|
||||||
item = utils.find_item(list["id"], self.session.db["lists"])
|
item = utils.find_item(list.id, self.session.db["lists"])
|
||||||
self.session.db["lists"].append(list)
|
self.session.db["lists"].append(list)
|
||||||
except TwythonError as e:
|
except TweepError as e:
|
||||||
output.speak("error %s: %s" % (e.status_code, e.msg))
|
output.speak("error %s: %s" % (e.api_code, e.reason))
|
||||||
|
|
||||||
def unsubscribe(self, *args, **kwargs):
|
def unsubscribe(self, *args, **kwargs):
|
||||||
if self.dialog.lista.get_count() == 0: return
|
if self.dialog.lista.get_count() == 0: return
|
||||||
list_id = self.lists[self.dialog.get_item()]["id"]
|
list_id = self.lists[self.dialog.get_item()].id
|
||||||
try:
|
try:
|
||||||
list = self.session.twitter.unsubscribe_from_list(list_id=list_id)
|
list = self.session.twitter.unsubscribe_list(list_id=list_id)
|
||||||
self.session.db["lists"].remove(list)
|
self.session.db["lists"].remove(list)
|
||||||
except TwythonError as e:
|
except TweepError as e:
|
||||||
output.speak("error %s: %s" % (e.status_code, e.msg))
|
output.speak("error %s: %s" % (e.api_code, e.reason))
|
||||||
|
@ -94,10 +94,10 @@ class editListDialog(createListDialog):
|
|||||||
|
|
||||||
def __init__(self, list, *args, **kwargs):
|
def __init__(self, list, *args, **kwargs):
|
||||||
super(editListDialog, self).__init__(*args, **kwargs)
|
super(editListDialog, self).__init__(*args, **kwargs)
|
||||||
self.SetTitle(_(u"Editing the list %s") % (list["name"]))
|
self.SetTitle(_(u"Editing the list %s") % (list.name))
|
||||||
self.name.ChangeValue(list["name"])
|
self.name.ChangeValue(list.name)
|
||||||
self.description.ChangeValue(list["description"])
|
self.description.ChangeValue(list.description)
|
||||||
if list["mode"] == "public":
|
if list.mode == "public":
|
||||||
self.public.SetValue(True)
|
self.public.SetValue(True)
|
||||||
else:
|
else:
|
||||||
self.private.SetValue(True)
|
self.private.SetValue(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user