diff --git a/src/controller/buffers.py b/src/controller/buffers.py index b1db8f8..fa06584 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from sessionmanager import session import widgetUtils import messages +import utils from wxUI.tabs import home from pubsub import pub +from sessionmanager import session class baseBuffer(object): def __init__(self, parent=None, name="", session=None, composefunc=None, *args, **kwargs): @@ -41,7 +42,13 @@ class baseBuffer(object): if p.message.get_response() == widgetUtils.OK: msg = p.message.get_text().encode("utf-8") privacy_opts = p.get_privacy_options() - self.session.post_wall_status(message=msg, friends_only=privacy_opts) + attachments = "" + urls = utils.find_urls_in_text(msg) + if len(urls) != 0: + if len(attachments) == 0: attachments = urls[0] + else: attachments += urls[0] + msg = msg.replace(urls[0], "") + self.session.post_wall_status(message=msg, friends_only=privacy_opts, attachments=attachments) pub.sendMessage("posted", buffer=self.name) diff --git a/src/utils.py b/src/utils.py index 6e94d7d..e35569a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,4 +1,8 @@ # -*- coding: utf-8 -*- +import re + +url_re = re.compile("(?:\w+://|www\.)[^ ,.?!#%=+][^ ]*") +bad_chars = '\'\\.,[](){}:;"' def seconds_to_string(seconds, precision=0): day = seconds // 86400 @@ -24,4 +28,7 @@ def seconds_to_string(seconds, precision=0): string += _(u"%s second") % sec_string else: string += _(u"%s seconds") % sec_string - return string \ No newline at end of file + return string + +def find_urls_in_text(text): + return [s.strip(bad_chars) for s in url_re.findall(text)] \ No newline at end of file