def get_attachments(self, post): attachments = [] if post.has_key("attachments"): for i in post["attachments"]: # We don't need the photos_list attachment, so skip it. if i["type"] == "photos_list": continue if i["type"] == "photo": if self.load_images == False: self.load_images = True self.images.append(i) attachments.append(add_attachment(i)) self.attachments.append(i) # Links in text are not treated like normal attachments, so we'll have to catch and add those to the list without title # We can't get a title because title is provided by the VK API and it will not work for links as simple text. urls = utils.find_urls_in_text(self.dialog.get("post_view")) print urls if len(urls) > 0: links = [] for i in urls: links.append({"link": {"title": _(U"Untitled link"), "url": i}, "type": "link"}) for i in links: attachments.append(add_attachment(i)) self.attachments.append(i) if len(self.attachments) > 0: self.dialog.attachments.list.Enable(True) self.dialog.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.open_attachment) self.dialog.insert_attachments(attachments)
def compose_tweet(tweet, db, relative_times): """ 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 system == "Windows": original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") if relative_times == True: ts = original_date.humanize(locale=languageHandler.getLanguage()) else: ts = original_date.replace(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) else: ts = tweet["created_at"] if tweet.has_key("message"): value = "message" else: value = "text" text = StripChars(tweet[value]) if tweet.has_key("sender"): source = "DM" if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"],) else: user = tweet["sender"]["name"] elif tweet.has_key("user"): user = tweet["user"]["name"] source = re.sub(r"(?s)<.*?>", "", tweet["source"]) try: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"])) except KeyError: pass #text = "%s" % (StripChars(tweet["text"])) if text[-1] in chars: text=text+"." urls = utils.find_urls_in_text(text) for url in range(0, len(urls)): try: text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) except IndexError: pass if config.app['app-settings']['handle_longtweets']: pass # return [user+", ", text, ts+", ", source] return [user+", ", text, ts+", ", source]
def do_last(self, p): msg = p.message.get_text().encode("utf-8") privacy_opts = p.get_privacy_options() attachments = "" if hasattr(p, "attachments"): attachments = self.upload_attachments(p.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) p.message.Destroy()
def compose_tweet(tweet, db, relative_times): """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" long = twishort.is_long(tweet) if long != False: tweet["long_uri"] = long if system == "Windows": original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") if relative_times == True: ts = original_date.humanize(locale=languageHandler.getLanguage()) else: ts = original_date.replace(seconds=db["utc_offset"]).format( _(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) else: ts = tweet["created_at"] text = StripChars(tweet["text"]) if tweet.has_key("sender"): source = "DM" if db["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"], ) else: user = tweet["sender"]["name"] elif tweet.has_key("user"): user = tweet["user"]["name"] source = re.sub(r"(?s)<.*?>", "", tweet["source"]) try: text = "rt @%s: %s" % ( tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"])) except KeyError: text = "%s" % (StripChars(tweet["text"])) if text[-1] in chars: text = text + "." urls = utils.find_urls_in_text(text) for url in range(0, len(urls)): try: text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) except IndexError: pass if config.app['app-settings'][ 'handle_longtweets'] and 'long_uri' in tweet: try: oldtext = text text = twishort.get_full_text(tweet['long_uri']) except: text = oldtext tweet["text"] = text return [user + ", ", tweet["text"], ts + ", ", source]
def compose_tweet(tweet, db): """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" original_date = arrow.get(tweet["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") if config.main["general"]["relative_times"] == True: ts = original_date.humanize(locale=languageHandler.getLanguage()) else: ts = original_date.replace(seconds=db.settings["utc_offset"]).format( _(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) text = StripChars(tweet["text"]) if tweet.has_key("sender"): source = "DM" if db.settings["user_name"] == tweet["sender"]["screen_name"]: user = _(u"Dm to %s ") % (tweet["recipient"]["name"], ) else: user = tweet["sender"]["name"] elif tweet.has_key("user"): user = tweet["user"]["name"] source = re.sub(r"(?s)<.*?>", "", tweet["source"]) try: text = "rt @%s: %s" % ( tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"])) except KeyError: text = "%s" % (StripChars(tweet["text"])) if text[-1] in chars: text = text + "." urls = utils.find_urls_in_text(text) for url in range(0, len(urls)): try: text = text.replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) except IndexError: pass tweet["text"] = text return [user + ", ", tweet["text"], ts + ", ", source]