Merge lp:~markjtully/gwibber/foursquare-comments into lp:gwibber

Proposed by Mark Tully
Status: Merged
Merged at revision: 1291
Proposed branch: lp:~markjtully/gwibber/foursquare-comments
Merge into: lp:gwibber
Diff against target: 125 lines (+51/-9)
1 file modified
gwibber/microblog/plugins/foursquare/__init__.py (+51/-9)
To merge this branch: bzr merge lp:~markjtully/gwibber/foursquare-comments
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+93718@code.launchpad.net

Description of the change

Updates for the Foursquare plugin:
1. Updated to use the new green & blue logo
2. Fixed a bug where ampersands in shouts & venues were causing problems
3. Added support for displaying of comments on posts

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Great work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/microblog/plugins/foursquare/__init__.py'
2--- gwibber/microblog/plugins/foursquare/__init__.py 2012-02-13 05:09:23 +0000
3+++ gwibber/microblog/plugins/foursquare/__init__.py 2012-02-19 02:06:18 +0000
4@@ -9,7 +9,7 @@
5
6 PROTOCOL_INFO = {
7 "name": "Foursquare",
8- "version": "3.0",
9+ "version": "4.0",
10
11 "config": [
12 "private:secret_token",
13@@ -54,16 +54,24 @@
14
15 shouttext = ""
16 text = ""
17+
18+ if data.has_key("shout"):
19+ shout = data["shout"]
20+ shout = shout.replace('& ', '& ')
21+
22 if data.has_key("venue"):
23+ venuename = data["venue"]["name"]
24+ venuename = venuename.replace('& ', '& ')
25+
26 if data.has_key("shout"):
27- shouttext += data["shout"] + "\n\n"
28- text += data["shout"] + "\n"
29+ shouttext += shout + "\n\n"
30+ text += shout + "\n"
31 if data["venue"].has_key("id"):
32 m["url"] = "https://foursquare.com/venue/%s" % data["venue"]["id"]
33 else:
34 m["url"] = "https://foursquare.com"
35- shouttext += "Checked in at <a href='" + m["url"] + "'>" + data["venue"]["name"] + "</a>"
36- text += "Checked in at " + data["venue"]["name"]
37+ shouttext += "Checked in at <a href='" + m["url"] + "'>" + venuename + "</a>"
38+ text += "Checked in at " + venuename
39 if data["venue"]["location"].has_key("address"):
40 shouttext += ", " + data["venue"]["location"]["address"]
41 text += ", " + data["venue"]["location"]["address"]
42@@ -81,8 +89,8 @@
43 shouttext += " for " + data["event"]["name"]
44 else:
45 if data.has_key("shout"):
46- shouttext += data["shout"] + "\n\n"
47- text += data["shout"] + "\n"
48+ shouttext += shout + "\n\n"
49+ text += shout + "\n"
50 else:
51 text= "Checked in off the grid"
52 shouttext= "Checked in off the grid"
53@@ -94,7 +102,7 @@
54 m["sender"] = {}
55 m["sender"]["id"] = data["user"]["id"]
56 m["sender"]["image"] = data["user"]["photo"]
57- m["sender"]["url"] = "https://foursquare.com/user/-%s" % data["user"]["id"]
58+ m["sender"]["url"] = data["user"]["canonicalUrl"]
59 if data["user"]["relationship"] == "self":
60 m["sender"]["is_me"] = True
61 else:
62@@ -106,7 +114,7 @@
63 fullname += data["user"]["lastName"]
64
65 if data.has_key("photos"):
66- if data["photos"]["count"] == 1:
67+ if data["photos"]["count"] > 0:
68 m["photo"] = {}
69 m["photo"]["url"] = ""
70 m["photo"]["picture"] = data["photos"]["items"][0]["url"]
71@@ -120,6 +128,34 @@
72 m["source"] = "<a href='" + data["source"]["url"] + "'>" + data["source"]["name"] + "</a>"
73 else:
74 m["source"] = "<a href='https://foursquare.com/'>Foursquare</a>"
75+
76+ if data.has_key("comments"):
77+ if data["comments"]["count"] > 0:
78+
79+ m["comments"] = []
80+ comments = self._get_comments(data["id"])
81+ for comment in comments:
82+ # Get the commenter's name
83+ fullname = ""
84+ if comment["user"].has_key("firstName"):
85+ fullname += comment["user"]["firstName"] + " "
86+ if comment["user"].has_key("lastName"):
87+ fullname += comment["user"]["lastName"]
88+
89+ # Create a sender
90+ sender = {
91+ "name" : fullname,
92+ "id" : comment["user"]["id"],
93+ "is_me": False,
94+ "image": comment["user"]["photo"],
95+ "url" : comment["user"]["canonicalUrl"]
96+ }
97+ # Create a comment
98+ m["comments"].append({
99+ "text" : comment["text"],
100+ "time" : comment["createdAt"],
101+ "sender": sender,
102+ })
103
104 return m
105
106@@ -129,6 +165,12 @@
107 else:
108 logger.error("Foursquare error %s", data)
109 return False
110+
111+ def _get_comments(self, checkin_id):
112+ url = "/".join((URL_PREFIX, "checkins", checkin_id))
113+ url = url + "?oauth_token=" + self.token
114+ data = network.Download(url, None, False).get_json()["response"]
115+ return data["checkin"]["comments"]["items"]
116
117 def _get(self, path, parse="message", post=False, single=False, **args):
118 url = "/".join((URL_PREFIX, path))
119
120=== modified file 'gwibber/microblog/plugins/foursquare/ui/icons/hicolor/16x16/apps/foursquare.png'
121Binary files gwibber/microblog/plugins/foursquare/ui/icons/hicolor/16x16/apps/foursquare.png 2012-02-16 06:00:43 +0000 and gwibber/microblog/plugins/foursquare/ui/icons/hicolor/16x16/apps/foursquare.png 2012-02-19 02:06:18 +0000 differ
122=== modified file 'gwibber/microblog/plugins/foursquare/ui/icons/hicolor/22x22/apps/foursquare.png'
123Binary files gwibber/microblog/plugins/foursquare/ui/icons/hicolor/22x22/apps/foursquare.png 2012-02-16 06:00:43 +0000 and gwibber/microblog/plugins/foursquare/ui/icons/hicolor/22x22/apps/foursquare.png 2012-02-19 02:06:18 +0000 differ
124=== modified file 'gwibber/microblog/plugins/foursquare/ui/icons/hicolor/32x32/apps/foursquare.png'
125Binary files gwibber/microblog/plugins/foursquare/ui/icons/hicolor/32x32/apps/foursquare.png 2012-02-16 06:00:43 +0000 and gwibber/microblog/plugins/foursquare/ui/icons/hicolor/32x32/apps/foursquare.png 2012-02-19 02:06:18 +0000 differ

Subscribers

People subscribed via source and target branches