Merge lp:~markjtully/gwibber/multiplenicks into lp:gwibber

Proposed by Mark Tully
Status: Merged
Merged at revision: 1326
Proposed branch: lp:~markjtully/gwibber/multiplenicks
Merge into: lp:gwibber
Diff against target: 49 lines (+16/-20)
1 file modified
gwibber/microblog/plugins/twitter/__init__.py (+16/-20)
To merge this branch: bzr merge lp:~markjtully/gwibber/multiplenicks
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+99618@code.launchpad.net

Description of the change

Fixes an issue where multiple occurances of the same twitter name in the same tweet are not properly formatted, leading to a blank tweet in the stream.

To post a comment you must log in.
lp:~markjtully/gwibber/multiplenicks updated
1324. By Mark Tully

Replace all instances of a hashtag's occurance in a tweet at once rather than one at a time. (Prevents replacement of a second instance of a hashtag being put in the wrong place leading to malformed html)

Revision history for this message
Ken VanDine (ken-vandine) wrote :

There is a missing ">" in the mentions replace, I am fixing it in my merge.

Thanks!

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/twitter/__init__.py'
2--- gwibber/microblog/plugins/twitter/__init__.py 2012-03-06 17:26:55 +0000
3+++ gwibber/microblog/plugins/twitter/__init__.py 2012-03-28 00:37:21 +0000
4@@ -89,29 +89,25 @@
5
6 #Get mention entries
7 if data["entities"].has_key("user_mentions"):
8+ names = []
9 for mention in data["entities"]["user_mentions"]:
10- try:
11- screen_name = mention["screen_name"].lower()
12- startindex = m["content"].lower().index("@" + screen_name) + 1
13- endindex = startindex + len(screen_name)
14- start = m["content"][0:startindex]
15- end = m["content"][endindex:]
16- m["content"] = start + "<a href='gwibber:/user?acct=" + m["account"] + "&name=@" + mention["screen_name"] + "'>" + mention["screen_name"] + "</a>" + end
17- except:
18- pass
19-
20+ if not mention["screen_name"] in names:
21+ try:
22+ m["content"] = m["content"].replace("@" + mention["screen_name"], "@<a href='gwibber:/user?acct=" + m["account"] + "&name=@" + mention["screen_name"] + "'>" + mention["screen_name"] + "</a")
23+ except:
24+ pass
25+ names.append(mention["screen_name"])
26+
27 #Get hashtag entities
28 if data["entities"].has_key("hashtags"):
29- for tags in data["entities"]["hashtags"]:
30- try:
31- text = tags["text"]
32- startindex = m["content"].index("#" + text) + 1
33- endindex = startindex + len(text)
34- start = m["content"][0:startindex]
35- end = m["content"][endindex:]
36- m["content"] = start + "<a href='gwibber:/tag?acct=" + m["account"] + "&query=" + text + "'>" + text + "</a>" + end
37- except:
38- pass
39+ hashtags = []
40+ for tag in data["entities"]["hashtags"]:
41+ if not tag["text"] in hashtags:
42+ try:
43+ m["content"] = m["content"].replace("#" + tag["text"], "#<a href='gwibber:/tag?acct=" + m["account"] + "&query=#" + tag["text"] + "'>" + tag["text"] + "</a>")
44+ except:
45+ pass
46+ hashtags.append(tag["text"])
47
48 # Get url entities - These usually go in the link stream, but if they're picturesor videos, they should go in the proper stream
49 if data["entities"].has_key("urls"):

Subscribers

People subscribed via source and target branches