Changed codebase's syntax before attempt the python3 migration later. #273

This commit is contained in:
Manuel Cortez 2018-11-22 13:35:19 -06:00
parent 4391e3d3de
commit 221d1d413b
53 changed files with 264 additions and 190 deletions

View File

@ -128,7 +128,7 @@ class baseBufferController(baseBuffers.buffer):
tweetsList = [] tweetsList = []
tweet_id = tweet["id"] tweet_id = tweet["id"]
message = None message = None
if tweet.has_key("message"): if "message" in tweet:
message = tweet["message"] message = tweet["message"]
try: try:
tweet = self.session.twitter.show_status(id=tweet_id, include_ext_alt_text=True, tweet_mode="extended") tweet = self.session.twitter.show_status(id=tweet_id, include_ext_alt_text=True, tweet_mode="extended")
@ -241,7 +241,7 @@ class baseBufferController(baseBuffers.buffer):
if self.name[:-9] in self.session.settings["other_buffers"]["timelines"]: if self.name[:-9] in self.session.settings["other_buffers"]["timelines"]:
self.session.settings["other_buffers"]["timelines"].remove(self.name[:-9]) self.session.settings["other_buffers"]["timelines"].remove(self.name[:-9])
self.session.settings.write() self.session.settings.write()
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
@ -254,7 +254,7 @@ class baseBufferController(baseBuffers.buffer):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-9] in self.session.settings["other_buffers"]["favourites_timelines"]: if self.name[:-9] in self.session.settings["other_buffers"]["favourites_timelines"]:
self.session.settings["other_buffers"]["favourites_timelines"].remove(self.name[:-9]) self.session.settings["other_buffers"]["favourites_timelines"].remove(self.name[:-9])
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write() self.session.settings.write()
return True return True
@ -377,7 +377,7 @@ class baseBufferController(baseBuffers.buffer):
self.show_menu(widgetUtils.MENU, pos=self.buffer.list.list.GetPosition()) self.show_menu(widgetUtils.MENU, pos=self.buffer.list.list.GetPosition())
def get_tweet(self): def get_tweet(self):
if self.session.db[self.name][self.buffer.list.get_selected()].has_key("retweeted_status"): if "retweeted_status" in self.session.db[self.name][self.buffer.list.get_selected()]:
tweet = self.session.db[self.name][self.buffer.list.get_selected()]["retweeted_status"] tweet = self.session.db[self.name][self.buffer.list.get_selected()]["retweeted_status"]
else: else:
tweet = self.session.db[self.name][self.buffer.list.get_selected()] tweet = self.session.db[self.name][self.buffer.list.get_selected()]
@ -392,7 +392,7 @@ class baseBufferController(baseBuffers.buffer):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
screen_name = tweet["user"]["screen_name"] screen_name = tweet["user"]["screen_name"]
id = tweet["id"] id = tweet["id"]
twishort_enabled = tweet.has_key("twishort") twishort_enabled = "twishort" in tweet
users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name") users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name")
ids = utils.get_all_mentioned(tweet, self.session.db, field="id_str") ids = utils.get_all_mentioned(tweet, self.session.db, field="id_str")
# Build the window title # Build the window title
@ -489,9 +489,9 @@ class baseBufferController(baseBuffers.buffer):
def _retweet_with_comment(self, tweet, id, comment=''): def _retweet_with_comment(self, tweet, id, comment=''):
# If quoting a retweet, let's quote the original tweet instead the retweet. # If quoting a retweet, let's quote the original tweet instead the retweet.
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
tweet = tweet["retweeted_status"] tweet = tweet["retweeted_status"]
if tweet.has_key("full_text"): if "full_text" in tweet:
comments = tweet["full_text"] comments = tweet["full_text"]
else: else:
comments = tweet["text"] comments = tweet["text"]
@ -723,7 +723,7 @@ class sentDirectMessagesController(directMessagesController):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(sentDirectMessagesController, self).__init__(*args, **kwargs) super(sentDirectMessagesController, self).__init__(*args, **kwargs)
if self.session.db.has_key("sent_direct_messages") == False: if ("sent_direct_messages" in self.session.db) == False:
self.session.db["sent_direct_messages"] = {"items": []} self.session.db["sent_direct_messages"] = {"items": []}
def get_more_items(self): def get_more_items(self):
@ -770,7 +770,7 @@ class listBufferController(baseBufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-5] in self.session.settings["other_buffers"]["lists"]: if self.name[:-5] in self.session.settings["other_buffers"]["lists"]:
self.session.settings["other_buffers"]["lists"].remove(self.name[:-5]) self.session.settings["other_buffers"]["lists"].remove(self.name[:-5])
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write() self.session.settings.write()
return True return True
@ -805,7 +805,7 @@ class peopleBufferController(baseBufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-10] in self.session.settings["other_buffers"]["followers_timelines"]: if self.name[:-10] in self.session.settings["other_buffers"]["followers_timelines"]:
self.session.settings["other_buffers"]["followers_timelines"].remove(self.name[:-10]) self.session.settings["other_buffers"]["followers_timelines"].remove(self.name[:-10])
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write() self.session.settings.write()
return True return True
@ -819,7 +819,7 @@ class peopleBufferController(baseBufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-8] in self.session.settings["other_buffers"]["friends_timelines"]: if self.name[:-8] in self.session.settings["other_buffers"]["friends_timelines"]:
self.session.settings["other_buffers"]["friends_timelines"].remove(self.name[:-8]) self.session.settings["other_buffers"]["friends_timelines"].remove(self.name[:-8])
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write() self.session.settings.write()
return True return True
@ -1000,7 +1000,7 @@ class searchBufferController(baseBufferController):
if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]: if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]:
self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11]) self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11])
self.session.settings.write() self.session.settings.write()
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
@ -1051,7 +1051,7 @@ class searchPeopleBufferController(peopleBufferController):
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
self.function = function self.function = function
if self.kwargs.has_key("page") == False: if ("page" in self.kwargs) == False:
self.kwargs["page"] = 1 self.kwargs["page"] = 1
def start_stream(self, mandatory=False, play_sound=True, avoid_autoreading=True): def start_stream(self, mandatory=False, play_sound=True, avoid_autoreading=True):
@ -1115,7 +1115,7 @@ class searchPeopleBufferController(peopleBufferController):
if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]: if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]:
self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11]) self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11])
self.session.settings.write() self.session.settings.write()
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
@ -1188,7 +1188,7 @@ class trendsBufferController(baseBuffers.buffer):
if self.name[:-3] in self.session.settings["other_buffers"]["trending_topic_buffers"]: if self.name[:-3] in self.session.settings["other_buffers"]["trending_topic_buffers"]:
self.session.settings["other_buffers"]["trending_topic_buffers"].remove(self.name[:-3]) self.session.settings["other_buffers"]["trending_topic_buffers"].remove(self.name[:-3])
self.session.settings.write() self.session.settings.write()
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
@ -1288,7 +1288,7 @@ class conversationBufferController(searchBufferController):
else: else:
dlg = widgetUtils.YES dlg = widgetUtils.YES
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.session.db.has_key(self.name): if self.name in self.session.db:
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:

View File

@ -30,7 +30,7 @@ class filter(object):
if i["name"] in langs: if i["name"] in langs:
langcodes.append(i["code"]) langcodes.append(i["code"])
d = dict(in_buffer=self.buffer.name, word=term, regexp=regexp, in_lang=lang_option, languages=langcodes, if_word_exists=contains, allow_rts=allow_rts, allow_quotes=allow_quotes, allow_replies=allow_replies) d = dict(in_buffer=self.buffer.name, word=term, regexp=regexp, in_lang=lang_option, languages=langcodes, if_word_exists=contains, allow_rts=allow_rts, allow_quotes=allow_quotes, allow_replies=allow_replies)
if self.buffer.session.settings["filters"].has_key(title): if title in self.buffer.session.settings["filters"]:
return commonMessageDialogs.existing_filter() return commonMessageDialogs.existing_filter()
self.buffer.session.settings["filters"][title] = d self.buffer.session.settings["filters"][title] = d
self.buffer.session.settings.write() self.buffer.session.settings.write()

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import platform import platform
system = platform.system() system = platform.system()
import application import application
@ -8,15 +9,15 @@ import arrow
if system == "Windows": if system == "Windows":
from update import updater from update import updater
from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon) from wxUI import (view, dialogs, commonMessageDialogs, sysTrayIcon)
import settings from . import settings
from extra import SoundsTutorial, ocr from extra import SoundsTutorial, ocr
import keystrokeEditor import keystrokeEditor
from keyboard_handler.wx_handler import WXKeyboardHandler from keyboard_handler.wx_handler import WXKeyboardHandler
import userActionsController from . import userActionsController
import trendingTopics from . import trendingTopics
import user from . import user
import listsController from . import listsController
import filterController from . import filterController
# from issueReporter import issueReporter # from issueReporter import issueReporter
elif system == "Linux": elif system == "Linux":
from gtkUI import (view, commonMessageDialogs) from gtkUI import (view, commonMessageDialogs)
@ -24,7 +25,7 @@ from sessions.twitter import utils, compose
from sessionmanager import manager, sessionManager from sessionmanager import manager, sessionManager
from controller.buffers import baseBuffers, twitterBuffers from controller.buffers import baseBuffers, twitterBuffers
import messages from . import messages
import sessions import sessions
from sessions.twitter import session as session_ from sessions.twitter import session as session_
from pubsub import pub from pubsub import pub
@ -392,7 +393,7 @@ class Controller(object):
def set_buffer_positions(self, session): def set_buffer_positions(self, session):
"Sets positions for buffers if values exist in the database." "Sets positions for buffers if values exist in the database."
for i in self.buffers: for i in self.buffers:
if i.account == session.db["user_name"] and session.db.has_key(i.name+"_pos") and hasattr(i.buffer,'list'): if i.account == session.db["user_name"] and i.name+"_pos" in session.db and hasattr(i.buffer,'list'):
i.buffer.list.select_item(session.db[str(i.name+"_pos")]) i.buffer.list.select_item(session.db[str(i.name+"_pos")])
def logout_account(self, session_id): def logout_account(self, session_id):
@ -1563,7 +1564,7 @@ class Controller(object):
output.speak(_(u"Invalid buffer")) output.speak(_(u"Invalid buffer"))
return return
tweet = buffer.get_tweet() tweet = buffer.get_tweet()
if tweet.has_key("entities") == False or tweet["entities"].has_key("media") == False: if ("entities" in tweet) == False or ("media" in tweet["entities"]) == False:
output.speak(_(u"This tweet doesn't contain images")) output.speak(_(u"This tweet doesn't contain images"))
return return
if len(tweet["entities"]["media"]) > 1: if len(tweet["entities"]["media"]) > 1:

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import re import re
import platform import platform
import attach from . import attach
import arrow import arrow
import languageHandler import languageHandler
system = platform.system() system = platform.system()
@ -206,25 +207,25 @@ class viewTweet(basicTweet):
text = "" text = ""
for i in xrange(0, len(tweetList)): for i in xrange(0, len(tweetList)):
# tweets with message keys are longer tweets, the message value is the full messaje taken from twishort. # tweets with message keys are longer tweets, the message value is the full messaje taken from twishort.
if tweetList[i].has_key("message") and tweetList[i]["is_quote_status"] == False: if "message" in tweetList[i] and tweetList[i]["is_quote_status"] == False:
value = "message" value = "message"
else: else:
value = "full_text" value = "full_text"
if tweetList[i].has_key("retweeted_status") and tweetList[i]["is_quote_status"] == False: if "retweeted_status" in tweetList[i] and tweetList[i]["is_quote_status"] == False:
if tweetList[i].has_key("message") == False: if ("message" in tweetList[i]) == False:
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["full_text"]) text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["full_text"])
else: else:
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value]) text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value])
else: else:
text = text + " @%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value]) text = text + " @%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value])
# tweets with extended_entities could include image descriptions. # tweets with extended_entities could include image descriptions.
if tweetList[i].has_key("extended_entities") and tweetList[i]["extended_entities"].has_key("media"): if "extended_entities" in tweetList[i] and "media" in tweetList[i]["extended_entities"]:
for z in tweetList[i]["extended_entities"]["media"]: for z in tweetList[i]["extended_entities"]["media"]:
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
if tweetList[i].has_key("retweeted_status") and tweetList[i]["retweeted_status"].has_key("extended_entities") and tweetList[i]["retweeted_status"]["extended_entities"].has_key("media"): if "retweeted_status" in tweetList[i] and "extended_entities" in tweetList[i]["retweeted_status"] and "media" in tweetList[i]["retweeted_status"]["extended_entities"]:
for z in tweetList[i]["retweeted_status"]["extended_entities"]["media"]: for z in tweetList[i]["retweeted_status"]["extended_entities"]["media"]:
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
# set rt and likes counters. # set rt and likes counters.
rt_count = str(tweet["retweet_count"]) rt_count = str(tweet["retweet_count"])
@ -234,25 +235,25 @@ class viewTweet(basicTweet):
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en")
date = original_date.replace(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage()) date = original_date.replace(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
if text == "": if text == "":
if tweet.has_key("message"): if "message" in tweet:
value = "message" value = "message"
else: else:
value = "full_text" value = "full_text"
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
if tweet.has_key("message") == False: if ("message" in tweet) == False:
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["full_text"]) text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["full_text"])
else: else:
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value]) text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value])
else: else:
text = tweet[value] text = tweet[value]
text = self.clear_text(text) text = self.clear_text(text)
if tweet.has_key("extended_entities") and tweet["extended_entities"].has_key("media"): if "extended_entities" in tweet and "media" in tweet["extended_entities"]:
for z in tweet["extended_entities"]["media"]: for z in tweet["extended_entities"]["media"]:
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
if tweet.has_key("retweeted_status") and tweet["retweeted_status"].has_key("extended_entities") and tweet["retweeted_status"]["extended_entities"].has_key("media"): if "retweeted_status" in tweet and "extended_entities" in tweet["retweeted_status"] and "media" in tweet["retweeted_status"]["extended_entities"]:
for z in tweet["retweeted_status"]["extended_entities"]["media"]: for z in tweet["retweeted_status"]["extended_entities"]["media"]:
if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8"), date) self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8"), date)
self.message.set_title(len(text)) self.message.set_title(len(text))

View File

@ -71,7 +71,7 @@ class userActionsController(object):
def ignore_client(self, user): def ignore_client(self, user):
tweet = self.buffer.get_right_tweet() tweet = self.buffer.get_right_tweet()
if tweet.has_key("sender"): if "sender" in tweet:
output.speak(_(u"You can't ignore direct messages")) output.speak(_(u"You can't ignore direct messages"))
return return
client = re.sub(r"(?s)<.*?>", "", tweet["source"]) client = re.sub(r"(?s)<.*?>", "", tweet["source"])

View File

@ -16,10 +16,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
from __future__ import absolute_import
import widgetUtils import widgetUtils
import wx_ui from . import wx_ui
import wx_transfer_dialogs from . import wx_transfer_dialogs
import transfer from . import transfer
import output import output
import tempfile import tempfile
import sound import sound

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import sys import sys
import threading import threading
import time import time
import logging import logging
from utils import convert_bytes from .utils import convert_bytes
from pubsub import pub from pubsub import pub
log = logging.getLogger("extra.AudioUploader.transfer") log = logging.getLogger("extra.AudioUploader.transfer")
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
@ -75,9 +76,9 @@ class Upload(object):
data = self.response.json() data = self.response.json()
except: except:
return _("Error in file upload: {0}").format(self.data.content,) return _("Error in file upload: {0}").format(self.data.content,)
if data.has_key("url") and data["url"] != "0": if "url" in data and data["url"] != "0":
return data["url"] return data["url"]
elif data.has_key("error") and data["error"] != "0": elif "error" in data and data["error"] != "0":
return data["error"] return data["error"]
else: else:
return _("Error in file upload: {0}").format(self.data.content,) return _("Error in file upload: {0}").format(self.data.content,)

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from utils import * from .utils import *
import widgetUtils import widgetUtils
class UploadDialog(widgetUtils.BaseDialog): class UploadDialog(widgetUtils.BaseDialog):

View File

@ -1 +1,2 @@
from soundsTutorial import soundsTutorial from __future__ import absolute_import
from .soundsTutorial import soundsTutorial

View File

@ -1,15 +1,16 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import platform import platform
import widgetUtils import widgetUtils
import os import os
import paths import paths
import logging import logging
log = logging.getLogger("extra.SoundsTutorial.soundsTutorial") log = logging.getLogger("extra.SoundsTutorial.soundsTutorial")
import soundsTutorial_constants from . import soundsTutorial_constants
if platform.system() == "Windows": if platform.system() == "Windows":
import wx_ui as UI from . import wx_ui as UI
elif platform.system() == "Linux": elif platform.system() == "Linux":
import gtk_ui as UI from . import gtk_ui as UI
class soundsTutorial(object): class soundsTutorial(object):
def __init__(self, sessionObject): def __init__(self, sessionObject):

View File

@ -1,5 +1,7 @@
#-*- coding: utf-8 -*- #-*- coding: utf-8 -*-
import reverse_sort from __future__ import absolute_import
#-*- coding: utf-8 -*-
from . import reverse_sort
import application import application
actions = reverse_sort.reverse_sort([ ("audio", _(u"Audio tweet.")), actions = reverse_sort.reverse_sort([ ("audio", _(u"Audio tweet.")),
("create_timeline", _(u"User timeline buffer created.")), ("create_timeline", _(u"User timeline buffer created.")),

View File

@ -1,4 +1,5 @@
import spellchecker from __future__ import absolute_import
from . import spellchecker
import platform import platform
if platform.system() == "Windows": if platform.system() == "Windows":
from wx_ui import * from .wx_ui import *

View File

@ -1,14 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import os import os
import logging import logging
import wx_ui from . import wx_ui
import widgetUtils import widgetUtils
import output import output
import config import config
import languageHandler import languageHandler
import enchant import enchant
import paths import paths
import twitterFilter from . import twitterFilter
from enchant.checker import SpellChecker from enchant.checker import SpellChecker
from enchant.errors import DictNotFoundError from enchant.errors import DictNotFoundError
from enchant import tokenize from enchant import tokenize
@ -52,7 +53,7 @@ class spellChecker(object):
def check(self): def check(self):
try: try:
self.checker.next() next(self.checker)
textToSay = _(u"Misspelled word: %s") % (self.checker.word,) textToSay = _(u"Misspelled word: %s") % (self.checker.word,)
context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10)) context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
self.dialog.set_title(textToSay) self.dialog.set_title(textToSay)

View File

@ -1,2 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import completion, settings from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import completion, settings

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import output import output
import storage from . import storage
import wx_menu from . import wx_menu
class autocompletionUsers(object): class autocompletionUsers(object):
def __init__(self, window, session_id): def __init__(self, window, session_id):

View File

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import storage from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import storage
import widgetUtils import widgetUtils
import wx_manage from . import wx_manage
from wxUI import commonMessageDialogs from wxUI import commonMessageDialogs
class autocompletionManage(object): class autocompletionManage(object):

View File

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import storage from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import storage
import widgetUtils import widgetUtils
import wx_settings from . import wx_settings
import manage from . import manage
import output import output
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded

View File

@ -1,2 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import OCRSpace from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import OCRSpace

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import translator from __future__ import absolute_import
from . import translator
import platform import platform
if platform.system() == "Windows": if platform.system() == "Windows":
import wx_ui as gui from . import wx_ui as gui

View File

@ -16,7 +16,26 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
import translator from __future__ import absolute_import
# -*- coding: utf-8 -*-
############################################################
# Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo <manuel@manuelcortez.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
from . import translator
import wx import wx
from wxUI.dialogs import baseDialog from wxUI.dialogs import baseDialog

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" This module contains some bugfixes for packages used in TWBlue.""" """ This module contains some bugfixes for packages used in TWBlue."""
from __future__ import absolute_import
import sys import sys
import fix_arrow # A few new locales for Three languages in arrow. from . import fix_arrow # A few new locales for Three languages in arrow.
import fix_urllib3_warnings # Avoiding some SSL warnings related to Twython. from . import fix_urllib3_warnings # Avoiding some SSL warnings related to Twython.
import fix_win32com from . import fix_win32com
import fix_requests #fix cacert.pem location for TWBlue binary copies from . import fix_requests #fix cacert.pem location for TWBlue binary copies
def setup(): def setup():
fix_arrow.fix() fix_arrow.fix()
if hasattr(sys, "frozen"): if hasattr(sys, "frozen"):

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from builtins import object
import application import application
import platform import platform
import exceptions import exceptions

View File

@ -1 +1,2 @@
from keystrokeEditor import KeystrokeEditor from __future__ import absolute_import
from .keystrokeEditor import KeystrokeEditor

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import widgetUtils import widgetUtils
import config import config
import wx_ui from . import wx_ui
import constants from . import constants
from pubsub import pub from pubsub import pub
class KeystrokeEditor(object): class KeystrokeEditor(object):

View File

@ -32,7 +32,7 @@ class keystrokeEditorDialog(baseDialog.BaseWXDialog):
selection = self.keys.get_selected() selection = self.keys.get_selected()
self.keys.clear() self.keys.clear()
for i in keystrokes: for i in keystrokes:
if actions.has_key(i) == False: if (i in actions) == False:
continue continue
action = actions[i] action = actions[i]
self.actions.append(i) self.actions.append(i)

View File

@ -1 +1,2 @@
import widgets from __future__ import absolute_import
from . import widgets

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" A cross platform notification system. """ A cross platform notification system.
Under Linux, the wx.NotificationMessage does not show a notification on the taskbar, so we decided to use dbus for showing notifications for linux and wx for Windows.""" Under Linux, the wx.NotificationMessage does not show a notification on the taskbar, so we decided to use dbus for showing notifications for linux and wx for Windows."""
from __future__ import absolute_import
import platform import platform
notify = None notify = None
@ -8,10 +9,10 @@ notify = None
def setup(): def setup():
global notify global notify
if platform.system() == "Windows": if platform.system() == "Windows":
import windows from . import windows
notify = windows.notification() notify = windows.notification()
elif platform.system() == "Linux": elif platform.system() == "Linux":
import linux from . import linux
notify = linux.notification() notify = linux.notification()
def send(title, text): def send(title, text):

View File

@ -1,20 +1,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import shutil import shutil
import widgetUtils import widgetUtils
import platform import platform
import output import output
if platform.system() == "Windows": if platform.system() == "Windows":
import wxUI as view from . import wxUI as view
from controller import settings from controller import settings
elif platform.system() == "Linux": elif platform.system() == "Linux":
import gtkUI as view from . import gtkUI as view
import paths import paths
import time import time
import os import os
import logging import logging
import sessions import sessions
from sessions.twitter import session from sessions.twitter import session
import manager from . import manager
import config_utils import config_utils
import config import config
@ -77,7 +78,7 @@ class sessionManagerController(object):
def do_ok(self): def do_ok(self):
log.debug("Starting sessions...") log.debug("Starting sessions...")
for i in self.sessions: for i in self.sessions:
if sessions.sessions.has_key(i) == True: continue if (i in sessions.sessions) == True: continue
s = session.Session(i) s = session.Session(i)
s.get_configuration() s.get_configuration()
if i not in config.app["sessions"]["ignored_sessions"]: if i not in config.app["sessions"]["ignored_sessions"]:

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" A base class to be derived in possible new sessions for TWBlue and services.""" """ A base class to be derived in possible new sessions for TWBlue and services."""
from __future__ import absolute_import
import paths import paths
import output import output
import time import time
@ -9,7 +10,7 @@ import config_utils
import shelve import shelve
import application import application
import os import os
import session_exceptions as Exceptions from . import session_exceptions as Exceptions
log = logging.getLogger("sessionmanager.session") log = logging.getLogger("sessionmanager.session")
class baseSession(object): class baseSession(object):

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import platform import platform
system = platform.system() system = platform.system()
import utils from . import utils
import re import re
import htmlentitydefs import htmlentitydefs
import time import time
@ -10,7 +11,7 @@ import languageHandler
import arrow import arrow
import logging import logging
import config import config
from long_tweets import twishort, tweets from .long_tweets import twishort, tweets
log = logging.getLogger("compose") log = logging.getLogger("compose")
def StripChars(s): def StripChars(s):
@ -38,13 +39,13 @@ def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=No
ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
else: else:
ts = tweet["created_at"] ts = tweet["created_at"]
if tweet.has_key("message"): if "message" in tweet:
value = "message" value = "message"
elif tweet.has_key("full_text"): elif "full_text" in tweet:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
if tweet.has_key("retweeted_status") and value != "message": if "retweeted_status" in tweet and value != "message":
text = StripChars(tweet["retweeted_status"][value]) text = StripChars(tweet["retweeted_status"][value])
else: else:
text = StripChars(tweet[value]) text = StripChars(tweet[value])
@ -53,16 +54,16 @@ def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=No
else: else:
user = tweet["user"]["name"] user = tweet["user"]["name"]
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) source = re.sub(r"(?s)<.*?>", "", tweet["source"])
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
if tweet.has_key("message") == False and tweet["retweeted_status"]["is_quote_status"] == False: if ("message" in tweet) == False and tweet["retweeted_status"]["is_quote_status"] == False:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text)
elif tweet["retweeted_status"]["is_quote_status"]: elif tweet["retweeted_status"]["is_quote_status"]:
text = "%s" % (text) text = "%s" % (text)
else: else:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text)
if tweet.has_key("message") == False: if ("message" in tweet) == False:
urls = utils.find_urls_in_text(text) urls = utils.find_urls_in_text(text)
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
for url in range(0, len(urls)): for url in range(0, len(urls)):
try: try:
text = text.replace(urls[url], tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]) text = text.replace(urls[url], tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"])
@ -110,14 +111,14 @@ def compose_direct_message(item, db, relative_times, show_screen_names=False, se
def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None): def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if quoted_tweet.has_key("retweeted_status"): if "retweeted_status" in quoted_tweet:
if quoted_tweet["retweeted_status"].has_key("full_text"): if "full_text" in quoted_tweet["retweeted_status"]:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
text = StripChars(quoted_tweet["retweeted_status"][value]) text = StripChars(quoted_tweet["retweeted_status"][value])
else: else:
if quoted_tweet.has_key("full_text"): if "full_text" in quoted_tweet:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -127,13 +128,13 @@ def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False,
else: else:
quoting_user = quoted_tweet["user"]["name"] quoting_user = quoted_tweet["user"]["name"]
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"]) source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"])
if quoted_tweet.has_key("retweeted_status"): if "retweeted_status" in quoted_tweet:
text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], text) text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], text)
if text[-1] in chars: text=text+"." if text[-1] in chars: text=text+"."
original_user = original_tweet["user"]["screen_name"] original_user = original_tweet["user"]["screen_name"]
if original_tweet.has_key("message"): if "message" in original_tweet:
original_text = original_tweet["message"] original_text = original_tweet["message"]
elif original_tweet.has_key("full_text"): elif "full_text" in original_tweet:
original_text = StripChars(original_tweet["full_text"]) original_text = StripChars(original_tweet["full_text"])
else: else:
original_text = StripChars(original_tweet["text"]) original_text = StripChars(original_tweet["text"])
@ -151,7 +152,7 @@ def compose_followers_list(tweet, db, relative_times=True, show_screen_names=Fal
ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
else: else:
ts = tweet["created_at"] ts = tweet["created_at"]
if tweet.has_key("status"): if "status" in tweet:
if len(tweet["status"]) > 4 and system == "Windows": if len(tweet["status"]) > 4 and system == "Windows":
original_date2 = arrow.get(tweet["status"]["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") original_date2 = arrow.get(tweet["status"]["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en")
if relative_times: if relative_times:

View File

@ -22,9 +22,9 @@ def is_long(tweet):
""" Check if the passed tweet contains a quote in its metadata. """ Check if the passed tweet contains a quote in its metadata.
tweet dict: a tweet dictionary. tweet dict: a tweet dictionary.
returns True if a quote is detected, False otherwise.""" returns True if a quote is detected, False otherwise."""
if tweet.has_key("quoted_status_id") and tweet.has_key("quoted_status"): if "quoted_status_id" in tweet and "quoted_status" in tweet:
return tweet["quoted_status_id"] return tweet["quoted_status_id"]
elif tweet.has_key("retweeted_status") and tweet["retweeted_status"].has_key("quoted_status_id") and tweet["retweeted_status"].has_key("quoted_status"): elif "retweeted_status" in tweet and "quoted_status_id" in tweet["retweeted_status"] and "quoted_status" in tweet["retweeted_status"]:
return tweet["retweeted_status"]["quoted_status_id"] return tweet["retweeted_status"]["quoted_status_id"]
return False return False
@ -32,8 +32,8 @@ def clear_url(tweet):
""" Reads data from a quoted tweet and removes the link to the Status from the tweet's text. """ Reads data from a quoted tweet and removes the link to the Status from the tweet's text.
tweet dict: a tweet dictionary. tweet dict: a tweet dictionary.
returns a tweet dictionary without the URL to the status ID in its text to display.""" returns a tweet dictionary without the URL to the status ID in its text to display."""
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
if tweet["retweeted_status"].has_key("full_text"): if "full_text" in tweet["retweeted_status"]:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -41,7 +41,7 @@ def clear_url(tweet):
try: tweet["message"] = tweet["message"].replace(urls[-1], "") try: tweet["message"] = tweet["message"].replace(urls[-1], "")
except IndexError: pass except IndexError: pass
else: else:
if tweet.has_key("full_text"): if "full_text" in tweet:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
from __future__ import print_function
import logging import logging
import requests import requests
import keys import keys
@ -47,7 +48,7 @@ def is_long(tweet):
# see https://github.com/manuelcortez/TWBlue/issues/103 # see https://github.com/manuelcortez/TWBlue/issues/103
except TypeError: except TypeError:
pass pass
if long == False and tweet.has_key("retweeted_status"): if long == False and "retweeted_status" in tweet:
for url in range(0, len(tweet["retweeted_status"]["entities"]["urls"])): for url in range(0, len(tweet["retweeted_status"]["entities"]["urls"])):
try: try:
if tweet["retweeted_status"]["entities"]["urls"][url] != None and "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]: if tweet["retweeted_status"]["entities"]["urls"][url] != None and "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]:
@ -97,5 +98,5 @@ def create_tweet(user_token, user_secret, text, media=0):
try: try:
return response.json()["text_to_tweet"] return response.json()["text_to_tweet"]
except: except:
print "There was a problem creating a long tweet" print("There was a problem creating a long tweet")
return 0 return 0

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" This is the main session needed to access all Twitter Features.""" """ This is the main session needed to access all Twitter Features."""
from __future__ import absolute_import
import os import os
import time import time
import logging import logging
@ -15,7 +16,7 @@ from keys import keyring
from sessions import base from sessions import base
from sessions.twitter import utils, compose from sessions.twitter import utils, compose
from sessions.twitter.long_tweets import tweets, twishort from sessions.twitter.long_tweets import tweets, twishort
from wxUI import authorisationDialog from .wxUI import authorisationDialog
log = logging.getLogger("sessions.twitterSession") log = logging.getLogger("sessions.twitterSession")
@ -30,9 +31,9 @@ class Session(base.baseSession):
returns the number of items that have been added in this execution""" returns the number of items that have been added in this execution"""
num = 0 num = 0
last_id = None last_id = None
if self.db.has_key(name) == False: if (name in self.db) == False:
self.db[name] = [] self.db[name] = []
if self.db.has_key("users") == False: if ("users" in self.db) == False:
self.db["users"] = {} self.db["users"] = {}
if ignore_older and len(self.db[name]) > 0: if ignore_older and len(self.db[name]) > 0:
if self.settings["general"]["reverse_timelines"] == False: if self.settings["general"]["reverse_timelines"] == False:
@ -51,8 +52,8 @@ class Session(base.baseSession):
if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i)
else: self.db[name].insert(0, i) else: self.db[name].insert(0, i)
num = num+1 num = num+1
if i.has_key("user") == True: if ("user" in i) == True:
if self.db["users"].has_key(i["user"]["id"]) == False: if (i["user"]["id"] in self.db["users"]) == False:
self.db["users"][i["user"]["id"]] = i["user"] self.db["users"][i["user"]["id"]] = i["user"]
return num return num
@ -66,7 +67,7 @@ class Session(base.baseSession):
if name == "direct_messages": if name == "direct_messages":
return self.order_direct_messages(data) return self.order_direct_messages(data)
num = 0 num = 0
if self.db.has_key(name) == False: if (name in self.db) == False:
self.db[name] = {} self.db[name] = {}
self.db[name]["items"] = [] self.db[name]["items"] = []
for i in data: for i in data:
@ -82,12 +83,12 @@ class Session(base.baseSession):
returns the number of incoming messages processed in this execution, and sends an event with data regarding amount of sent direct messages added.""" returns the number of incoming messages processed in this execution, and sends an event with data regarding amount of sent direct messages added."""
incoming = 0 incoming = 0
sent = 0 sent = 0
if self.db.has_key("direct_messages") == False: if ("direct_messages" in self.db) == False:
self.db["direct_messages"] = {} self.db["direct_messages"] = {}
self.db["direct_messages"]["items"] = [] self.db["direct_messages"]["items"] = []
for i in data: for i in data:
if i["message_create"]["sender_id"] == self.db["user_id"]: if i["message_create"]["sender_id"] == self.db["user_id"]:
if self.db.has_key("sent_direct_messages") and utils.find_item(i["id"], self.db["sent_direct_messages"]["items"]) == None: if "sent_direct_messages" in self.db and utils.find_item(i["id"], self.db["sent_direct_messages"]["items"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i)
else: self.db["sent_direct_messages"]["items"].insert(0, i) else: self.db["sent_direct_messages"]["items"].insert(0, i)
sent = sent+1 sent = sent+1
@ -164,13 +165,13 @@ class Session(base.baseSession):
users, dm bool: If any of these is set to True, the function will treat items as users or dm (they need different handling). users, dm bool: If any of these is set to True, the function will treat items as users or dm (they need different handling).
name str: name of the database item to put new element in.""" name str: name of the database item to put new element in."""
results = [] results = []
if kwargs.has_key("cursor") and kwargs["cursor"] == 0: if "cursor" in kwargs and kwargs["cursor"] == 0:
output.speak(_(u"There are no more items to retrieve in this buffer.")) output.speak(_(u"There are no more items to retrieve in this buffer."))
return return
data = getattr(self.twitter, update_function)(*args, **kwargs) data = getattr(self.twitter, update_function)(*args, **kwargs)
if users == True: if users == True:
if type(data) == dict and data.has_key("next_cursor"): if type(data) == dict and "next_cursor" in data:
if data.has_key("next_cursor"): # There are more objects to retrieve. if "next_cursor" in data: # There are more objects to retrieve.
self.db[name]["cursor"] = data["next_cursor"] self.db[name]["cursor"] = data["next_cursor"]
else: # Set cursor to 0, wich means no more items available. else: # Set cursor to 0, wich means no more items available.
self.db[name]["cursor"] = 0 self.db[name]["cursor"] = 0
@ -178,7 +179,7 @@ class Session(base.baseSession):
elif type(data) == list: elif type(data) == list:
results.extend(data[1:]) results.extend(data[1:])
elif dm == True: elif dm == True:
if data.has_key("next_cursor"): # There are more objects to retrieve. if "next_cursor" in data: # There are more objects to retrieve.
self.db[name]["cursor"] = data["next_cursor"] self.db[name]["cursor"] = data["next_cursor"]
else: # Set cursor to 0, wich means no more items available. else: # Set cursor to 0, wich means no more items available.
self.db[name]["cursor"] = 0 self.db[name]["cursor"] = 0
@ -289,7 +290,7 @@ class Session(base.baseSession):
name str: Name to save items to 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
if self.db.has_key(name): if name in self.db:
try: try:
if self.db[name][0]["id"] > self.db[name][-1]["id"]: if self.db[name][0]["id"] > self.db[name][-1]["id"]:
last_id = self.db[name][0]["id"] last_id = self.db[name][0]["id"]
@ -309,7 +310,7 @@ class Session(base.baseSession):
returns number of items retrieved.""" returns number of items retrieved."""
items_ = [] items_ = []
try: try:
if self.db[name].has_key("cursor") and get_previous: if "cursor" in self.db[name] and get_previous:
cursor = self.db[name]["cursor"] cursor = self.db[name]["cursor"]
else: else:
cursor = -1 cursor = -1
@ -322,7 +323,7 @@ class Session(base.baseSession):
tl[items].reverse() tl[items].reverse()
num = self.order_cursored_buffer(name, tl[items]) num = self.order_cursored_buffer(name, tl[items])
# Recently, Twitter's new endpoints have cursor if there are more results. # Recently, Twitter's new endpoints have cursor if there are more results.
if tl.has_key("next_cursor"): if "next_cursor" in tl:
self.db[name]["cursor"] = tl["next_cursor"] self.db[name]["cursor"] = tl["next_cursor"]
else: else:
self.db[name]["cursor"] = 0 self.db[name]["cursor"] = 0
@ -352,7 +353,7 @@ class Session(base.baseSession):
def get_quoted_tweet(self, tweet): def get_quoted_tweet(self, tweet):
""" Process a tweet and extract all information related to the quote.""" """ Process a tweet and extract all information related to the quote."""
quoted_tweet = tweet quoted_tweet = tweet
if tweet.has_key("full_text"): if "full_text" in tweet:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -360,16 +361,16 @@ class Session(base.baseSession):
for url in range(0, len(urls)): for url in range(0, len(urls)):
try: quoted_tweet[value] = quoted_tweet[value].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"]) try: quoted_tweet[value] = quoted_tweet[value].replace(urls[url], quoted_tweet["entities"]["urls"][url]["expanded_url"])
except IndexError: pass except IndexError: pass
if quoted_tweet.has_key("quoted_status"): if "quoted_status" in quoted_tweet:
original_tweet = quoted_tweet["quoted_status"] original_tweet = quoted_tweet["quoted_status"]
elif quoted_tweet.has_key("retweeted_status") and quoted_tweet["retweeted_status"].has_key("quoted_status"): elif "retweeted_status" in quoted_tweet and "quoted_status" in quoted_tweet["retweeted_status"]:
original_tweet = quoted_tweet["retweeted_status"]["quoted_status"] original_tweet = quoted_tweet["retweeted_status"]["quoted_status"]
else: else:
return quoted_tweet return quoted_tweet
original_tweet = self.check_long_tweet(original_tweet) original_tweet = self.check_long_tweet(original_tweet)
if original_tweet.has_key("full_text"): if "full_text" in original_tweet:
value = "full_text" value = "full_text"
elif original_tweet.has_key("message"): elif "message" in original_tweet:
value = "message" value = "message"
else: else:
value = "text" value = "text"
@ -386,13 +387,13 @@ class Session(base.baseSession):
long = twishort.is_long(tweet) long = twishort.is_long(tweet)
if long != False and config.app["app-settings"]["handle_longtweets"]: if long != False and config.app["app-settings"]["handle_longtweets"]:
message = twishort.get_full_text(long) message = twishort.get_full_text(long)
if tweet.has_key("quoted_status"): if "quoted_status" in tweet:
tweet["quoted_status"]["message"] = message tweet["quoted_status"]["message"] = message
if tweet["quoted_status"]["message"] == False: return False if tweet["quoted_status"]["message"] == False: return False
tweet["quoted_status"]["twishort"] = True tweet["quoted_status"]["twishort"] = True
for i in tweet["quoted_status"]["entities"]["user_mentions"]: for i in tweet["quoted_status"]["entities"]["user_mentions"]:
if "@%s" % (i["screen_name"]) not in tweet["quoted_status"]["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i["screen_name"]) not in tweet["quoted_status"]["message"] and i["screen_name"] != tweet["user"]["screen_name"]:
if tweet["quoted_status"].has_key("retweeted_status") and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if "retweeted_status" in tweet["quoted_status"] and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]:
continue continue
tweet["quoted_status"]["message"] = u"@%s %s" % (i["screen_name"], tweet["message"]) tweet["quoted_status"]["message"] = u"@%s %s" % (i["screen_name"], tweet["message"])
else: else:
@ -401,7 +402,7 @@ class Session(base.baseSession):
tweet["twishort"] = True tweet["twishort"] = True
for i in tweet["entities"]["user_mentions"]: for i in tweet["entities"]["user_mentions"]:
if "@%s" % (i["screen_name"]) not in tweet["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i["screen_name"]) not in tweet["message"] and i["screen_name"] != tweet["user"]["screen_name"]:
if tweet.has_key("retweeted_status") and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if "retweeted_status" in tweet and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]:
continue continue
return tweet return tweet
@ -409,7 +410,7 @@ class Session(base.baseSession):
""" Returns an user object associated with an ID. """ Returns an user object associated with an ID.
id str: User identifier, provided by Twitter. id str: User identifier, provided by Twitter.
returns an user dict.""" returns an user dict."""
if self.db.has_key("users") == False or self.db["users"].has_key(id) == False: if ("users" in self.db) == False or (id in self.db["users"]) == False:
user = self.twitter.show_user(id=id) user = self.twitter.show_user(id=id)
self.db["users"][user["id_str"]] = user self.db["users"][user["id_str"]] = user
return user return user
@ -420,7 +421,7 @@ class Session(base.baseSession):
""" Returns an user identifier associated with a screen_name. """ Returns an user identifier associated with a screen_name.
screen_name str: User name, such as tw_blue2, provided by Twitter. screen_name str: User name, such as tw_blue2, provided by Twitter.
returns an user ID.""" returns an user ID."""
if self.db.has_key("users") == False: if ("users" in self.db) == False:
user = utils.if_user_exists(self.twitter, screen_name) user = utils.if_user_exists(self.twitter, screen_name)
self.db["users"][user["id_str"]] = user self.db["users"][user["id_str"]] = user
return user["id_str"] return user["id_str"]

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
import url_shortener, re import url_shortener, re
import output import output
from twython import TwythonError from twython import TwythonError
@ -24,32 +25,32 @@ def find_urls_in_text(text):
def find_urls (tweet): def find_urls (tweet):
urls = [] urls = []
# Let's add URLS from tweet entities. # Let's add URLS from tweet entities.
if tweet.has_key("message_create"): if "message_create" in tweet:
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet["message_create"]["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet["entities"]
for i in entities["urls"]: for i in entities["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if tweet.has_key("quoted_status"): if "quoted_status" in tweet:
for i in tweet["quoted_status"]["entities"]["urls"]: for i in tweet["quoted_status"]["entities"]["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
for i in tweet["retweeted_status"]["entities"]["urls"]: for i in tweet["retweeted_status"]["entities"]["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if tweet["retweeted_status"].has_key("quoted_status"): if "quoted_status" in tweet["retweeted_status"]:
for i in tweet["retweeted_status"]["quoted_status"]["entities"]["urls"]: for i in tweet["retweeted_status"]["quoted_status"]["entities"]["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if tweet.has_key("message"): if "message" in tweet:
i = "message" i = "message"
elif tweet.has_key("full_text"): elif "full_text" in tweet:
i = "full_text" i = "full_text"
else: else:
i = "text" i = "text"
if tweet.has_key("message_create"): if "message_create" in tweet:
extracted_urls = find_urls_in_text(tweet["message_create"]["message_data"]["text"]) extracted_urls = find_urls_in_text(tweet["message_create"]["message_data"]["text"])
else: else:
extracted_urls = find_urls_in_text(tweet[i]) extracted_urls = find_urls_in_text(tweet[i])
@ -82,7 +83,7 @@ def is_audio(tweet):
try: try:
if len(find_urls(tweet)) < 1: if len(find_urls(tweet)) < 1:
return False return False
if tweet.has_key("message_create"): if "message_create" in tweet:
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet["message_create"]["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet["entities"]
@ -91,22 +92,22 @@ def is_audio(tweet):
if i["text"] == "audio": if i["text"] == "audio":
return True return True
except IndexError: except IndexError:
print tweet["entities"]["hashtags"] print(tweet["entities"]["hashtags"])
log.exception("Exception while executing is_audio hashtag algorithm") log.exception("Exception while executing is_audio hashtag algorithm")
def is_geocoded(tweet): def is_geocoded(tweet):
if tweet.has_key("coordinates") and tweet["coordinates"] != None: if "coordinates" in tweet and tweet["coordinates"] != None:
return True return True
def is_media(tweet): def is_media(tweet):
if tweet.has_key("message_create"): if "message_create" in tweet:
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet["message_create"]["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet["entities"]
if entities.has_key("media") == False: if ("media" in entities) == False:
return False return False
for i in entities["media"]: for i in entities["media"]:
if i.has_key("type") and i["type"] == "photo": if "type" in i and i["type"] == "photo":
return True return True
return False return False
@ -121,10 +122,10 @@ def get_all_mentioned(tweet, conf, field="screen_name"):
def get_all_users(tweet, conf): def get_all_users(tweet, conf):
string = [] string = []
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
string.append(tweet["user"]["screen_name"]) string.append(tweet["user"]["screen_name"])
tweet = tweet["retweeted_status"] tweet = tweet["retweeted_status"]
if tweet.has_key("sender"): if "sender" in tweet:
string.append(tweet["sender"]["screen_name"]) string.append(tweet["sender"]["screen_name"])
else: else:
if tweet["user"]["screen_name"] != conf["user_name"]: if tweet["user"]["screen_name"] != conf["user_name"]:
@ -161,16 +162,16 @@ def api_call(parent=None, call_name=None, preexec_message="", success="", succes
def is_allowed(tweet, settings, buffer_name): def is_allowed(tweet, settings, buffer_name):
clients = settings["twitter"]["ignored_clients"] clients = settings["twitter"]["ignored_clients"]
if tweet.has_key("sender"): return True if "sender" in tweet: return True
allowed = True allowed = True
tweet_data = {} tweet_data = {}
if tweet.has_key("retweeted_status"): if "retweeted_status" in tweet:
tweet_data["retweet"] = True tweet_data["retweet"] = True
if tweet["in_reply_to_status_id_str"] != None: if tweet["in_reply_to_status_id_str"] != None:
tweet_data["reply"] = True tweet_data["reply"] = True
if tweet.has_key("quoted_status"): if "quoted_status" in tweet:
tweet_data["quote"] = True tweet_data["quote"] = True
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"] if "retweeted_status" in tweet: tweet = tweet["retweeted_status"]
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) source = re.sub(r"(?s)<.*?>", "", tweet["source"])
for i in clients: for i in clients:
if i.lower() == source.lower(): if i.lower() == source.lower():
@ -178,7 +179,7 @@ def is_allowed(tweet, settings, buffer_name):
return filter_tweet(tweet, tweet_data, settings, buffer_name) return filter_tweet(tweet, tweet_data, settings, buffer_name)
def filter_tweet(tweet, tweet_data, settings, buffer_name): def filter_tweet(tweet, tweet_data, settings, buffer_name):
if tweet.has_key("full_text"): if "full_text" in tweet:
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -187,23 +188,23 @@ def filter_tweet(tweet, tweet_data, settings, buffer_name):
regexp = settings["filters"][i]["regexp"] regexp = settings["filters"][i]["regexp"]
word = settings["filters"][i]["word"] word = settings["filters"][i]["word"]
# Added if/else for compatibility reasons. # Added if/else for compatibility reasons.
if settings["filters"][i].has_key("allow_rts"): if "allow_rts" in settings["filters"][i]:
allow_rts = settings["filters"][i]["allow_rts"] allow_rts = settings["filters"][i]["allow_rts"]
else: else:
allow_rts = "True" allow_rts = "True"
if settings["filters"][i].has_key("allow_quotes"): if "allow_quotes" in settings["filters"][i]:
allow_quotes = settings["filters"][i]["allow_quotes"] allow_quotes = settings["filters"][i]["allow_quotes"]
else: else:
allow_quotes = "True" allow_quotes = "True"
if settings["filters"][i].has_key("allow_replies"): if "allow_replies" in settings["filters"][i]:
allow_replies = settings["filters"][i]["allow_replies"] allow_replies = settings["filters"][i]["allow_replies"]
else: else:
allow_replies = "True" allow_replies = "True"
if allow_rts == "False" and tweet_data.has_key("retweet"): if allow_rts == "False" and "retweet" in tweet_data:
return False return False
if allow_quotes == "False" and tweet_data.has_key("quote"): if allow_quotes == "False" and "quote" in tweet_data:
return False return False
if allow_replies == "False" and tweet_data.has_key("reply"): if allow_replies == "False" and "reply" in tweet_data:
return False return False
if word != "" and settings["filters"][i]["if_word_exists"]: if word != "" and settings["filters"][i]["if_word_exists"]:
if word in tweet[value]: if word in tweet[value]:

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import application import application
import update from . import update
import platform import platform
import logging import logging
import output import output
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
from wxUpdater import * from .wxUpdater import *
logger = logging.getLogger("updater") logger = logging.getLogger("updater")
def do_update(endpoint=application.update_url): def do_update(endpoint=application.update_url):

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
import application import application
import utils from . import utils
progress_dialog = None progress_dialog = None

View File

@ -1,5 +1,6 @@
from __future__ import absolute_import
import platform import platform
if platform.system() == "Windows": if platform.system() == "Windows":
from wxUtils import * from .wxUtils import *
#elif platform.system() == "Linux": #elif platform.system() == "Linux":
# from gtkUtils import * # from gtkUtils import *

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from base import basePanel from __future__ import absolute_import
from dm import dmPanel from .base import basePanel
from events import eventsPanel from .dm import dmPanel
from favourites import favsPanel from .events import eventsPanel
from lists import listPanel from .favourites import favsPanel
from panels import accountPanel, emptyPanel from .lists import listPanel
from people import peoplePanel from .panels import accountPanel, emptyPanel
from trends import trendsPanel from .people import peoplePanel
from tweet_searches import searchPanel from .trends import trendsPanel
from user_searches import searchUsersPanel from .tweet_searches import searchPanel
from .user_searches import searchUsersPanel

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from base import basePanel from .base import basePanel
class dmPanel(basePanel): class dmPanel(basePanel):
def __init__(self, parent, name): def __init__(self, parent, name):

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from base import basePanel from .base import basePanel
class favsPanel(basePanel): class favsPanel(basePanel):
def __init__(self, parent, name): def __init__(self, parent, name):

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from base import basePanel from .base import basePanel
class listPanel(basePanel): class listPanel(basePanel):
def __init__(self, parent, name): def __init__(self, parent, name):

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from multiplatform_widgets import widgets from multiplatform_widgets import widgets
from base import basePanel from .base import basePanel
class peoplePanel(basePanel): class peoplePanel(basePanel):
""" Buffer used to show people.""" """ Buffer used to show people."""

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from base import basePanel from .base import basePanel
class searchPanel(basePanel): class searchPanel(basePanel):
def __init__(self, parent, name): def __init__(self, parent, name):

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
from tweet_searches import searchPanel from .tweet_searches import searchPanel
from multiplatform_widgets import widgets from multiplatform_widgets import widgets
class searchUsersPanel(searchPanel): class searchUsersPanel(searchPanel):

View File

@ -1 +1,2 @@
import baseDialog, trends, configuration, lists, message, search, find, show_user, update_profile, urlList, userSelection, utils, filterDialogs from __future__ import absolute_import
from . import baseDialog, trends, configuration, lists, message, search, find, show_user, update_profile, urlList, userSelection, utils, filterDialogs

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging as original_logger import logging as original_logger
import wx import wx
import application import application
import output import output
import config import config
import widgetUtils import widgetUtils
import baseDialog from . import baseDialog
from multiplatform_widgets import widgets from multiplatform_widgets import widgets
class general(wx.Panel, baseDialog.BaseWXDialog): class general(wx.Panel, baseDialog.BaseWXDialog):

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import baseDialog from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import baseDialog
import wx import wx
import widgetUtils import widgetUtils
from multiplatform_widgets import widgets from multiplatform_widgets import widgets

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import baseDialog from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import baseDialog
import wx import wx
class findDialog(baseDialog.BaseWXDialog): class findDialog(baseDialog.BaseWXDialog):

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import widgetUtils import widgetUtils
import baseDialog from . import baseDialog
import wx import wx
from extra import translator from extra import translator

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
import baseDialog from . import baseDialog
class showUserProfile(baseDialog.BaseWXDialog): class showUserProfile(baseDialog.BaseWXDialog):
def __init__(self): def __init__(self):

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import baseDialog from __future__ import absolute_import
# -*- coding: utf-8 -*-
from . import baseDialog
import wx import wx
class trendingTopicsDialog(baseDialog.BaseWXDialog): class trendingTopicsDialog(baseDialog.BaseWXDialog):

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import wx import wx
import baseDialog from . import baseDialog
class updateProfileDialog(baseDialog.BaseWXDialog): class updateProfileDialog(baseDialog.BaseWXDialog):
def __init__(self): def __init__(self):

View File

@ -16,8 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
from __future__ import absolute_import
import wx import wx
import baseDialog from . import baseDialog
class selectUserDialog(baseDialog.BaseWXDialog): class selectUserDialog(baseDialog.BaseWXDialog):
def __init__(self, title, users): def __init__(self, title, users):