Merge lp:~george-edison55/askubuntu-lens/askubuntu-lens-local-search into lp:~stefano-palazzo/askubuntu-lens/trunk

Proposed by Nathan Osman
Status: Merged
Merged at revision: 46
Proposed branch: lp:~george-edison55/askubuntu-lens/askubuntu-lens-local-search
Merge into: lp:~stefano-palazzo/askubuntu-lens/trunk
Diff against target: 41 lines (+20/-11)
1 file modified
askubuntu_bridge.py (+20/-11)
To merge this branch: bzr merge lp:~george-edison55/askubuntu-lens/askubuntu-lens-local-search
Reviewer Review Type Date Requested Status
Stefano Palazzo Pending
Review via email: mp+80770@code.launchpad.net

Description of the change

I have added code to the askubuntu_bridge.py file that will cause the lens to first attempt to retrieve the data from the local server where possible and failing that to try the other servers as per usual.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'askubuntu_bridge.py'
2--- askubuntu_bridge.py 2011-10-18 02:14:00 +0000
3+++ askubuntu_bridge.py 2011-10-31 04:56:22 +0000
4@@ -103,17 +103,26 @@
5 print "api.%s/\33[1;31m%s\33[m" % (site, query)
6 if query.startswith("similar?title") and site == "askubuntu.com":
7 try:
8- if random.random() > 0.5:
9- result = json.loads(urllib2.urlopen(
10- "http://50.19.108.78:8080/%s" % query.replace(" ", "%20"),
11- timeout=0.5).read())
12- print "\33[1mused ec2 service\33[m"
13- else:
14- result = json.loads(urllib2.urlopen(
15- "http://audata.quickmediasolutions.com:8046/%s" % query.replace(" ", "%20"),
16- timeout=0.5).read())
17- print "\33[1mused AU Data Server service\33[m"
18- return result
19+ # Check to see if we can ping the local data server running on
20+ # port 19115
21+ try:
22+ result = json.loads(urllib2.urlopen(
23+ "http://localhost:19115/%s" % query.replace(" ", "%20"),
24+ timeout=0.2).read())
25+ print "\33[1mused local service\33[m"
26+ return result
27+ except Exception as e:
28+ if random.random() > 0.5:
29+ result = json.loads(urllib2.urlopen(
30+ "http://50.19.108.78:8080/%s" % query.replace(" ", "%20"),
31+ timeout=0.5).read())
32+ print "\33[1mused ec2 service\33[m"
33+ else:
34+ result = json.loads(urllib2.urlopen(
35+ "http://audata.quickmediasolutions.com:8046/%s" % query.replace(" ", "%20"),
36+ timeout=0.5).read())
37+ print "\33[1mused AU Data Server service\33[m"
38+ return result
39 except Exception as e:
40 print "\33[1;31m%s\33[m" % repr(e)
41 try:

Subscribers

People subscribed via source and target branches

to all changes: