def _story(self, data): m = {}; m["mid"] = str(data["id"]) m["service"] = "digg" m["account"] = self.account["id"] m["time"] = data["submit_date"] m["text"] = data["title"] + "\n" + data["description"] m["content"] = "<b>%(title)s</b><br />%(description)s" % data m["html"] = "<b>%(title)s</b><br />%(description)s" % data user = data["friends"]["users"][0] m["sender"] = {} m["sender"]["nick"] = user["name"] m["sender"]["id"] = user["name"] m["sender"]["image"] = user["icon"] m["sender"]["url"] = "http://digg.com/users/%s" % user["name"] m["sender"]["is_me"] = user["name"] == self.account["username"] if user.get("fullname", 0): m["sender"]["name"] = user["fullname"] m["url"] = data["link"] m["likes"] = {"count": data["diggs"]} 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))) 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"]))) 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, entry): m = {} try: m['mid'] = entry.id m['service'] = 'yaru' m['account'] = self.account['id'] m['time'] = mktime(entry.updated.timetuple()) m['text'] = entry.content m['to_me'] = ('@%s' % self.account['username']) in entry.content m['html'] = linkify(entry.content) m['content'] = linkify(entry.content) m['url'] = entry.links['alternate'] except: log.logger.error('%s failure - %s', PROTOCOL_INFO['name'], entry) 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 _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 _story(self, data): m = {} m["mid"] = str(data["id"]) m["service"] = "digg" m["account"] = self.account["id"] m["time"] = data["submit_date"] m["text"] = data["title"] + "\n" + data["description"] m["content"] = "<b>%(title)s</b><br />%(description)s" % data m["html"] = "<b>%(title)s</b><br />%(description)s" % data user = data["friends"]["users"][0] m["sender"] = {} m["sender"]["nick"] = user["name"] m["sender"]["id"] = user["name"] m["sender"]["image"] = user["icon"] m["sender"]["url"] = "http://digg.com/users/%s" % user["name"] m["sender"]["is_me"] = user["name"] == self.account["username"] if user.get("fullname", 0): m["sender"]["name"] = user["fullname"] m["url"] = data["link"] m["likes"] = {"count": data["diggs"]} 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), ), ) 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"]), ), ) return m
def _message(self, data): if type(data) != dict: log.logger.error("Cannot parse message data: %s", str(data)) return {} m = {} m["mid"] = str(data["id"]) m["service"] = "facebook" m["account"] = self.account["id"] m["time"] = int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))) m["url"] = "https://facebook.com/" + data["id"].split("_")[0] + "/posts/" + data["id"].split("_")[1] if data.get("attribution", 0): m["source"] = util.strip_urls(data["attribution"]).replace("via ", "") if data.has_key("message"): m["to_me"] = ("@%s" % self.account["username"]) in data["message"] if data.get("message", "").strip(): m["text"] = data["message"] m["html"] = util.linkify(data["message"]) m["content"] = m["html"] else: m["text"] = "" m["html"] = "" m["content"] = "" m["sender"] = self._sender(data["from"]) m["type"] = data["type"] if data["type"] == "photo": m["photo"] = {} m["photo"]["picture"] = data.get("picture", None) m["photo"]["url"] = data.get("link", None) m["photo"]["name"] = data.get("name", None) if data["type"] == "video": m["video"] = {} m["video"]["picture"] = data.get("picture", None) m["video"]["source"] = data.get("source", None) m["video"]["url"] = data.get("link", None) m["video"]["name"] = data.get("name", None) m["video"]["icon"] = data.get("icon", None) m["video"]["properties"] = data.get("properties", {}) if data["type"] == "link": m["link"] = {} m["link"]["picture"] = data.get("picture", None) m["link"]["name"] = data.get("name", None) m["link"]["description"] = data.get("description", None) m["link"]["url"] = data.get("link", None) m["link"]["icon"] = data.get("icon", None) m["link"]["caption"] = data.get("caption", None) m["link"]["properties"] = data.get("properties", {}) if data.has_key("privacy"): m["privacy"] = {} m["privacy"]["description"] = data["privacy"]["description"] m["privacy"]["value"] = data["privacy"]["value"] # Handle target for wall posts with a specific recipient if data.has_key("to"): m["sender"]["name"] += u" \u25b8 %s" % (data["to"]["data"][0]["name"]) if data.has_key("likes"): m["likes"] = {} if isinstance(data["likes"], dict): m["likes"]["count"] = data["likes"]["count"] m["likes"]["data"] = data["likes"]["data"] else: m["likes"]["count"] = data["likes"] if data.get("comments", 0): m["comments"] = [] if data["comments"].has_key("data"): for item in data["comments"]["data"]: m["comments"].append( { "text": item["message"], "time": int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))), "sender": self._sender(item["from"]), } ) if data.get("attachment", 0): if data["attachment"].get("name", 0): m["content"] += "<p><b>%s</b></p>" % data["attachment"]["name"] if data["attachment"].get("description", 0): m["content"] += "<p>%s</p>" % data["attachment"]["description"] 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): if type(data) != dict: logger.error("Cannot parse message data: %s", str(data)) return {} m = {} m["mid"] = str(data["id"]) m["service"] = "facebook" m["account"] = self.account["id"] m["time"] = int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))) m["url"] = "https://facebook.com/" + data["id"].split("_")[0] + "/posts/" + data["id"].split("_")[1] if data.get("attribution", 0): m["source"] = util.strip_urls(data["attribution"]).replace("via ", "") if data.has_key("message"): m["to_me"] = ("@%s" % self.account["username"]) in data["message"] if data.get("message", "").strip(): m["text"] = data["message"] m["html"] = util.linkify(data["message"]) m["content"] = m["html"] else: m["text"] = "" m["html"] = "" m["content"] = "" m["sender"] = self._sender(data["from"]) m["type"] = data["type"] if data["type"] == "checkin": m["location"] = {} if isinstance(data["place"], dict): m["location"]["id"] = data["place"]["id"] m["location"]["name"] = data["place"].get("name", None) if m["location"]["name"]: m["html"] += " " + _("at") + " <p><b>%s</b></p>" % m["location"]["name"] m["content"] = m["html"] m["text"] += " " + _("at") + " " + m["location"]["name"] if data["place"].has_key("location"): m["location"]["latitude"] = data["place"]["location"].get("latitude", None) m["location"]["longitude"] = data["place"]["location"].get("longitude", None) m["location"]["city"] = data["place"]["location"].get("city", None) m["location"]["state"] = data["place"]["location"].get("state", None) m["location"]["country"] = data["place"]["location"].get("country", None) elif data["type"] == "photo": m["photo"] = {} m["photo"]["picture"] = data.get("picture", None) m["photo"]["url"] = data.get("link", None) m["photo"]["name"] = data.get("name", None) elif data["type"] == "video": m["video"] = {} m["video"]["picture"] = data.get("picture", None) m["video"]["source"] = data.get("source", None) m["video"]["url"] = data.get("link", None) m["video"]["name"] = data.get("name", None) m["video"]["icon"] = data.get("icon", None) m["video"]["properties"] = data.get("properties", {}) elif data["type"] == "link": m["link"] = {} m["link"]["picture"] = data.get("picture", None) m["link"]["name"] = data.get("name", None) m["link"]["description"] = data.get("description", None) m["link"]["url"] = data.get("link", None) m["link"]["icon"] = data.get("icon", None) m["link"]["caption"] = data.get("caption", None) m["link"]["properties"] = data.get("properties", {}) elif data["type"] == "question": m["question"] = {} m["question"]["id"] = data["id"] m["question"]["text"] = data.get("question", None) if not m["question"]["text"]: m["question"]["text"] = data.get("story", None) if data.has_key("options") and isinstance(data["options"], dict): if isinstance(data["options"]["data"], dict): m["question"]["answers"] = [] for a in data["options"]["data"]: answer = {} answer["id"] = a.get("id", None) answer["name"] = a.get("name", None) answer["votes"] = a.get("votes", None) m["question"]["answers"].append(answer) if m["question"]["text"] and len(m["text"]) < 1: m["text"] = m["question"]["text"] m["html"] = m["text"] m["content"] = m["html"] elif data["type"] == "status": pass else: logger.error ("facebook: unexpected type %s", data["type"]) if data.has_key("privacy"): m["privacy"] = {} m["privacy"]["description"] = data["privacy"]["description"] m["privacy"]["value"] = data["privacy"]["value"] # Handle target for wall posts with a specific recipient if data.has_key("to"): m["sender"]["name"] += u" \u25b8 %s"%(data["to"]["data"][0]["name"]) if data.has_key("likes"): m["likes"] = {} m["likes"]["liked"] = False if isinstance(data["likes"], dict): m["likes"]["count"] = data["likes"]["count"] if data["likes"].has_key("data"): m["likes"]["data"] = data["likes"]["data"] for d in m["likes"]["data"]: if self.user_id == str(d["id"]): m["likes"]["liked"] = True else: m["likes"]["count"] = data["likes"] if data.get("comments", 0): m["comments"] = [] if data["comments"].has_key("data"): for item in data["comments"]["data"]: m["comments"].append({ "text": item["message"], "time": int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))), "sender": self._sender(item["from"]), }) if data.get("attachment", 0): if data["attachment"].get("name", 0): m["content"] += "<p><b>%s</b></p>" % data["attachment"]["name"] if data["attachment"].get("description", 0): m["content"] += "<p>%s</p>" % data["attachment"]["description"] return m
def _message(self, data): m = {} m["mid"] = str(data["id"]) m["service"] = "facebook" m["account"] = self.account["id"] m["time"] = int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))) m["url"] = "https://facebook.com/" + data["id"].split("_")[0] + "/posts/" + data["id"].split("_")[1] if data.get("attribution", 0): m["source"] = util.strip_urls(data["attribution"]).replace("via ", "") if data.has_key("message"): m["to_me"] = ("@%s" % self.account["username"]) in data["message"] if data.get("message", "").strip(): m["text"] = data["message"] m["html"] = util.linkify(data["message"]) m["content"] = m["html"] else: m["text"] = "" m["html"] = "" m["content"] = "" m["sender"] = self._sender(data["from"]) m["type"] = data["type"] if data["type"] == "photo": m["photo"] = {} m["photo"]["picture"] = data.get("picture", None) m["photo"]["url"] = data.get("link", None) m["photo"]["name"] = data.get("name", None) if data["type"] == "video": m["video"] = {} m["video"]["picture"] = data.get("picture", None) m["video"]["source"] = data.get("source", None) m["video"]["url"] = data.get("link", None) m["video"]["name"] = data.get("name", None) m["video"]["icon"] = data.get("icon", None) m["video"]["properties"] = data.get("properties", {}) if data["type"] == "link": m["link"] = {} m["link"]["picture"] = data.get("picture", None) m["link"]["name"] = data.get("name", None) m["link"]["description"] = data.get("description", None) m["link"]["url"] = data.get("link", None) m["link"]["icon"] = data.get("icon", None) m["link"]["caption"] = data.get("caption", None) m["link"]["properties"] = data.get("properties", {}) if data.has_key("privacy"): m["privacy"] = {} m["privacy"]["description"] = data["privacy"]["description"] m["privacy"]["value"] = data["privacy"]["value"] # Handle target for wall posts with a specific recipient if data.has_key("to"): m["sender"]["name"] += u" \u25b8 %s"%(data["to"]["data"][0]["name"]) if data.has_key("likes"): m["likes"] = {} if isinstance(data["likes"], dict): m["likes"]["count"] = data["likes"]["count"] m["likes"]["data"] = data["likes"]["data"] else: m["likes"]["count"] = data["likes"] if data.get("comments", 0): m["comments"] = [] if data["comments"].has_key("data"): for item in data["comments"]["data"]: m["comments"].append({ "text": item["message"], "time": int(mx.DateTime.DateTimeFrom(str(data.get("updated_time", data["created_time"])))), "sender": self._sender(item["from"]), }) if data.get("attachment", 0): if data["attachment"].get("name", 0): m["content"] += "<p><b>%s</b></p>" % data["attachment"]["name"] if data["attachment"].get("description", 0): m["content"] += "<p>%s</p>" % data["attachment"]["description"] return m