The first URL will be posted as attachment

This commit is contained in:
Manuel Cortez 2016-02-14 19:24:45 -06:00
parent bc5e76ce1c
commit abfb232cab
2 changed files with 17 additions and 3 deletions

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from sessionmanager import session
import widgetUtils import widgetUtils
import messages import messages
import utils
from wxUI.tabs import home from wxUI.tabs import home
from pubsub import pub from pubsub import pub
from sessionmanager import session
class baseBuffer(object): class baseBuffer(object):
def __init__(self, parent=None, name="", session=None, composefunc=None, *args, **kwargs): 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: if p.message.get_response() == widgetUtils.OK:
msg = p.message.get_text().encode("utf-8") msg = p.message.get_text().encode("utf-8")
privacy_opts = p.get_privacy_options() 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) pub.sendMessage("posted", buffer=self.name)

View File

@ -1,4 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
url_re = re.compile("(?:\w+://|www\.)[^ ,.?!#%=+][^ ]*")
bad_chars = '\'\\.,[](){}:;"'
def seconds_to_string(seconds, precision=0): def seconds_to_string(seconds, precision=0):
day = seconds // 86400 day = seconds // 86400
@ -25,3 +29,6 @@ def seconds_to_string(seconds, precision=0):
else: else:
string += _(u"%s seconds") % sec_string string += _(u"%s seconds") % sec_string
return string return string
def find_urls_in_text(text):
return [s.strip(bad_chars) for s in url_re.findall(text)]