def _message(self, data): if type(data) != dict: logger.error("Cannot parse message data: %s", str(data)) return {} n = {} if data.has_key("retweeted_status"): n["retweeted_by"] = self._user(data["user"] if "user" in data else data["sender"]) if data.has_key("created_at"): n["time"] = util.parsetime(data["created_at"]) data = data["retweeted_status"] else: n["retweeted_by"] = None if data.has_key("created_at"): n["time"] = util.parsetime(data["created_at"]) m = self._common(data) for k in n: m[k] = n[k] if data.has_key("in_reply_to_status_id"): if data["in_reply_to_status_id"]: m["reply"] = {} m["reply"]["id"] = data["in_reply_to_status_id"] m["reply"]["nick"] = data["in_reply_to_screen_name"] if m["reply"]["id"] and m["reply"]["nick"]: m["reply"]["url"] = "/".join((self.url_prefix, "notice", str(m["reply"]["id"]))) else: m["reply"]["url"] = None m["sender"] = self._user(data["user"] if "user" in data else data["sender"]) m["url"] = "/".join((self.url_prefix, "notice", str(m["mid"]))) return m
def _common(self, data): m = {} try: m["mid"] = str(data["id"]) m["service"] = "identica" m["account"] = self.account["id"] m["time"] = util.parsetime(data["created_at"]) m["source"] = data.get("source", False) m["text"] = data["text"] m["to_me"] = ("@%s" % self.account["username"]) in data["text"] m["html"] = util.linkify(m["text"], ((util.PARSE_HASH, '#<a class="hash" href="%s#search?q=\\1">\\1</a>' % self.url_prefix), (util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % self.url_prefix))) m["content"] = util.linkify(m["text"], ((util.PARSE_HASH, '#<a class="hash" href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]), (util.PARSE_NICK, '@<a class="nick" href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"]))) images = [] if data.get("attachments", 0): for a in data["attachments"]: mime = a.get("mimetype", "") if mime and mime.startswith("image") and a.get("url", 0): images.append({"src": a["url"], "url": a["url"]}) images.extend(util.imgpreview(m["text"])) if images: m["images"] = images m["type"] = "photo" except: log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data) return m
def _common(self, data): m = {}; try: m["mid"] = str(data["id"]) m["service"] = "twitter" m["account"] = self.account["id"] if data.has_key("created_at"): m["time"] = util.parsetime(data["created_at"]) m["text"] = util.unescape(data["text"]) m["to_me"] = ("@%s" % self.account["username"]) in data["text"] m["html"] = util.linkify(m["text"], ((util.PARSE_HASH, '#<a class="hash" href="%s#search?q=\\1">\\1</a>' % URL_PREFIX), (util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % URL_PREFIX)), escape=False) m["content"] = util.linkify(m["text"], ((util.PARSE_HASH, '#<a href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]), (util.PARSE_NICK, '@<a href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=True) m["favorited"] = data.get("favorited", False) images = util.imgpreview(m["text"]) if images: m["images"] = images m["type"] = "photo" except: log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data) return {} return m
def _common(self, data): m = {} m["mid"] = str(data["id"]) m["service"] = "qaiku" m["account"] = self.account["id"] m["time"] = util.parsetime(data["created_at"]) m["text"] = data["text"] m["to_me"] = ("@%s" % self.account["username"]) in data["text"] m["html"] = data["html"] # TODO: Change Qaiku's @-links to people to Gwibber-internal ones m["content"] = data["html"] if (data["external_url"]): # Qaiku posts can have external links in them, display that under the message m["content"] += "<p><a href=\"" + data[ "external_url"] + "\">" + data["external_url"] + "</a></p>" # TODO: Display picture Qaikus if "channel" in data and data["channel"]: # Put message's Qaiku channel as "source" so it will be displayed in the UI m["source"] = "<a href=\"http://www.qaiku.com/channels/show/" + data[ "channel"] + "/\">#" + data["channel"] + "</a>" if "in_reply_to_status_id" in data and data["in_reply_to_status_id"]: m["reply"] = {} m["reply"]["id"] = data["in_reply_to_status_id"] m["reply"]["nick"] = data["in_reply_to_screen_name"] m["reply"]["url"] = data["in_reply_to_status_url"] return m
def _common(self, data): m = {}; m["mid"] = str(data["id"]) m["service"] = "qaiku" m["account"] = self.account["id"] m["time"] = util.parsetime(data["created_at"]) m["text"] = data["text"] m["to_me"] = ("@%s" % self.account["username"]) in data["text"] m["html"] = data["html"] # TODO: Change Qaiku's @-links to people to Gwibber-internal ones m["content"] = data["html"] if (data["external_url"]): # Qaiku posts can have external links in them, display that under the message m["content"] += "<p><a href=\"" + data["external_url"] + "\">" + data["external_url"] + "</a></p>" # TODO: Display picture Qaikus if "channel" in data and data["channel"]: # Put message's Qaiku channel as "source" so it will be displayed in the UI m["source"] = "<a href=\"http://www.qaiku.com/channels/show/" + data["channel"] + "/\">#" + data["channel"] + "</a>" if "in_reply_to_status_id" in data and data["in_reply_to_status_id"]: m["reply"] = {} m["reply"]["id"] = data["in_reply_to_status_id"] m["reply"]["nick"] = data["in_reply_to_screen_name"] m["reply"]["url"] = data["in_reply_to_status_url"] return m
def _message(self, data): m = { "mid": data["id"], "service": "friendfeed", "account": self.account["id"], "time": util.parsetime(data["published"]), "source": data.get("via", {}).get("name", None), "text": data["title"], "html": util.linkify(data["title"]), "content": util.linkify(data["title"]), "url": data["link"], "sender": self._sender(data["user"]), } if data.get("service", 0): m["origin"] = { "id": data["service"]["id"], "name": data["service"]["name"], "icon": data["service"]["iconUrl"], "url": data["service"]["profileUrl"], } if data.get("likes", 0): m["likes"] = {"count": len(data["likes"])} if data.get("comments", 0): m["comments"] = [] for item in data["comments"][-3:]: m["comments"].append({ "text": item["body"], "time": util.parsetime(item["date"]), "sender": self._sender(item["user"]), }) for i in data["media"]: if i.get("thumbnails", 0): m["images"] = [] for t in i["thumbnails"]: m["images"].append({"src": t["url"], "url": i["link"]}) if data.get("geo", 0): m["location"] = data["geo"] return m
def _message(self, data): m = { "mid": data["id"], "service": "buzz", "account": self.account["id"], "time": util.parsetime(data["published"]), "url": data.get("links", {})["alternate"][0].get("href", ""), "source": data.get("source", {}).get("title", None), "sender": self._actor(data["actor"]), } m["text"] = data["object"]["content"] if data.get("source", {}).get("title", 0) == "Twitter": m["text"] = m["text"].split(">:", 1)[1].strip() m["html"] = m["text"] m["content"] = m["text"] if data.get("geocode", 0): m["location"] = { "lat": data["geocode"].split()[0], "lon": data["geocode"].split()[1], } if data.get("address", 0): m["location"]["address"] = data["address"] m["images"] = [] for a in data["object"].get("attachments", []): if a["type"] == "photo": m["images"].append({ "src": a["links"]["preview"][0]["href"], "url": a["links"]["enclosure"][0]["href"] }) if a["type"] == "video": m["images"].append({ "src": a["links"]["preview"][0]["href"], "url": a["links"]["alternate"][0]["href"], }) if a["type"] == "article": m["content"] += "<p><b><a href=\"%s\">%s</a></b></p>" % (a["links"]["alternate"][0]["href"], a["title"]) return m
def _common(self, data): m = {} try: m["mid"] = str(data["id"]) m["service"] = "twitter" m["account"] = self.account["id"] m["time"] = util.parsetime(data["created_at"]) m["text"] = unescape(data["text"]) m["to_me"] = ("@%s" % self.account["username"]) in data["text"] m["html"] = util.linkify( data["text"], ((util.PARSE_HASH, '#<a class="hash" href="%s#search?q=\\1">\\1</a>' % URL_PREFIX), (util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % URL_PREFIX)), escape=False) m["content"] = util.linkify(data["text"], (( util.PARSE_HASH, '#<a class="hash" href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"] ), (util.PARSE_NICK, '@<a class="nick" href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=False) if data.has_key("retweeted_status"): m["retweeted_status"] = data["retweeted_status"] else: m["retweeted_status"] = None images = util.imgpreview(m["text"]) if images: m["images"] = images m["type"] = "photo" except: log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data) return {} return m
def _common(self, data): m = {} try: m["mid"] = str(data["id"]) m["service"] = "twitter" m["account"] = self.account["id"] if data.has_key("created_at"): m["time"] = util.parsetime(data["created_at"]) m["text"] = util.unescape(data["text"]) m["text"] = cgi.escape(m["text"]) m["content"] = m["text"] # Go through the entities in the tweet and use them to linkify/filter tweeks as appropriate if data.has_key("entities"): #Get mention entries if data["entities"].has_key("user_mentions"): names = [] for mention in data["entities"]["user_mentions"]: if not mention["screen_name"] in names: try: m["content"] = m["content"].replace("@" + mention["screen_name"], "@<a href='gwibber:/user?acct=" + m["account"] + "&name=@" + mention["screen_name"] + "'>" + mention["screen_name"] + "</a>") except: pass names.append(mention["screen_name"]) #Get hashtag entities if data["entities"].has_key("hashtags"): hashtags = [] for tag in data["entities"]["hashtags"]: if not tag["text"] in hashtags: try: m["content"] = m["content"].replace("#" + tag["text"], "#<a href='gwibber:/tag?acct=" + m["account"] + "&query=#" + tag["text"] + "'>" + tag["text"] + "</a>") except: pass hashtags.append(tag["text"]) # Get url entities - These usually go in the link stream, but if they're picturesor videos, they should go in the proper stream if data["entities"].has_key("urls"): for urls in data["entities"]["urls"]: url = cgi.escape (urls["url"]) expanded_url = url if urls.has_key("expanded_url"): if not urls["expanded_url"] is None: expanded_url = cgi.escape(urls["expanded_url"]) display_url = url if urls.has_key("display_url"): display_url = cgi.escape (urls["display_url"]) if url == m["content"]: m["content"] = "<a href='" + url + "' title='" + expanded_url + "'>" + display_url + "</a>" else: try: startindex = m["content"].index(url) endindex = startindex + len(url) start = m["content"][0:startindex] end = m["content"][endindex:] m["content"] = start + "<a href='" + url + "' title='" + expanded_url + "'>" + display_url + "</a>" + end except: logger.debug ("Failed to set url for ID: %s", m["mid"]) m["type"] = "link" images = util.imgpreview(expanded_url) videos = util.videopreview(expanded_url) if images: m["images"] = images m["type"] = "photo" elif videos: m["images"] = videos m["type"] = "video" else: # Well, it's not anything else, so it must be a link m["link"] = {} m["link"]["picture"] = "" m["link"]["name"] = "" m["link"]["description"] = m["content"] m["link"]["url"] = url m["link"]["icon"] = "" m["link"]["caption"] = "" m["link"]["properties"] = {} if data["entities"].has_key("media"): for media in data["entities"]["media"]: try: url = cgi.escape (media["url"]) media_url_https = media["media_url_https"] expanded_url = url if media.has_key("expanded_url"): expanded_url = cgi.escape(media["expanded_url"]) display_url = url if media.has_key("display_url"): display_url = cgi.escape (media["display_url"]) startindex = m["content"].index(url) endindex = startindex + len(url) start = m["content"][0:startindex] end = m["content"][endindex:] m["content"] = start + "<a href='" + url + "' title='" + expanded_url + "'>" + display_url + "</a>" + end if media["type"] == "photo": m["type"] = "photo" m["photo"] = {} m["photo"]["picture"] = media_url_https m["photo"]["url"] = None m["photo"]["name"] = None except: pass else: m["content"] = util.linkify(util.unescape(m["text"]), ((util.PARSE_HASH, '#<a href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]), (util.PARSE_NICK, '@<a href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=True) m["html"] = m["content"] m["to_me"] = ("@%s" % self.account["username"]) in data["text"] # Check if it's a reply directed at the user m["favorited"] = data.get("favorited", False) # Check if the tweet has been favourited except: logger.error("%s failure - %s", PROTOCOL_INFO["name"], data) return {} return m
def _message(self, data): m = {} m["mid"] = str(data["id"]) m["service"] = "foursquare" m["account"] = self.account["id"] m["time"] = util.parsetime(data["created"]) shouttext = "" text = "" if data.has_key("venue"): if data.has_key("shout"): shouttext += data["shout"] + "<br/><br/>" text += data["shout"] + "\n" if data["venue"].has_key("id"): m["url"] = "http://foursquare.com/venue/%s" % data["venue"][ "id"] else: m["url"] = "http://foursquare.com" if data["venue"].has_key("primarycategory"): img = "<table><tr><td><img src='%s'/></td><td>" % data[ "venue"]["primarycategory"]["iconurl"] else: img = "<table><tr><td><img src='http://foursquare.com/img/categories/none.png'/></td><td>" shouttext += img + "Checked in at <a href='" + m[ "url"] + "'>" + data["venue"]["name"] + "</a>" text += "Checked in at " + data["venue"]["name"] if data["venue"].has_key("address"): shouttext += ", " + data["venue"]["address"] text += ", " + data["venue"]["address"] if data["venue"].has_key("crossstreet"): shouttext += " and " + data["venue"]["crossstreet"] text += " and " + data["venue"]["crossstreet"] if data["venue"].has_key("city"): shouttext += ", " + data["venue"]["city"] text += ", " + data["venue"]["city"] if data["venue"].has_key("state"): shouttext += ", " + data["venue"]["state"] text += ", " + data["venue"]["state"] else: if data.has_key("shout"): shouttext += data["shout"] + "<br/><br/>" text += data["shout"] + "\n" else: text = "Checked in off the grid" shouttext = "<table><tr><td><img src='http://foursquare.com/img/categories/question.png'/></td><td>Checked in off the grid" m["text"] = text m["content"] = shouttext + "</td></tr></table>" m["html"] = shouttext + "</td></tr></table>" m["sender"] = {} m["sender"]["id"] = data["user"]["id"] m["sender"]["image"] = data["user"]["photo"] m["sender"][ "url"] = "http://foursquare.com/user/-%s" % data["user"]["id"] if data["user"]["friendstatus"] == "self": m["sender"]["is_me"] = True fullname = "" if data["user"].has_key("firstname"): fullname += data["user"]["firstname"] + " " if data["user"].has_key("lastname"): fullname += data["user"]["lastname"] m["sender"]["name"] = fullname m["sender"]["nick"] = fullname m["source"] = "<a href='http://foursquare.com/'>Foursquare</a>" return m