1
from gwibber.microblog import network, util
2
from gwibber.microblog.util import resources
3
from gettext import lgettext as _
27
URL_PREFIX = "http://services.digg.com"
30
def __init__(self, acct):
33
def _story(self, data):
35
m["mid"] = str(data["id"])
37
m["account"] = self.account["id"]
38
m["time"] = data["submit_date"]
40
m["text"] = data["title"] + "\n" + data["description"]
41
m["content"] = "<b>%(title)s</b><br />%(description)s" % data
42
m["html"] = "<b>%(title)s</b><br />%(description)s" % data
43
user = data["friends"]["users"][0]
46
m["sender"]["nick"] = user["name"]
47
m["sender"]["id"] = user["name"]
48
m["sender"]["image"] = user["icon"]
49
m["sender"]["url"] = "http://digg.com/users/%s" % user["name"]
50
m["sender"]["is_me"] = user["name"] == self.account["username"]
51
if user.get("fullname", 0): m["sender"]["name"] = user["fullname"]
53
m["url"] = data["link"]
54
m["likes"] = {"count": data["diggs"]}
56
m["html"] = util.linkify(m["text"],
57
((util.PARSE_HASH, '#<a class="hash" href="%s#search?q=\\1">\\1</a>' % URL_PREFIX),
58
(util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % URL_PREFIX)))
60
m["content"] = util.linkify(m["text"],
61
((util.PARSE_HASH, '#<a class="hash" href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]),
62
(util.PARSE_NICK, '@<a class="nick" href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])))
66
def _get(self, path, parse="story", post=False, single=False, **args):
67
url = "/".join((URL_PREFIX, path)) + "?appkey=http://gwibber.com&type=json"
69
data = network.Download(url, util.compact(args) or None, post).get_json()
71
if not data: return []
74
if single: return [getattr(self, "_%s" % parse)(data["stories"])]
75
if parse: return [getattr(self, "_%s" % parse)(m) for m in data["stories"]]
78
if ("status" in data) and ("message" in data):
79
print "Digg: got message with status %s and message %s" % (data["status"], data["message"])
82
def __call__(self, opname, **args):
83
return getattr(self, opname)(**args)
86
return self._get("user/%s/friends/dugg" % self.account["username"])