Merge lp:~strycore/lolz/quickly_trunk into lp:lolz

Proposed by Mathieu Comandon on 2010-01-23
Status: Needs review
Proposed branch: lp:~strycore/lolz/quickly_trunk
Merge into: lp:lolz
Diff against target: 343 lines (+64/-140) 6 files modified
To merge this branch: bzr merge lp:~strycore/lolz/quickly_trunk
Reviewer Review Type Date Requested Status
Mathieu Comandon (community) Approve on 2010-01-23
Review via email: mp+17951@code.launchpad.net

Commit Message

lolz , now with lolcats again, and it does not fail at getting pictures who fail

To post a comment you must log in.
review: Approve

Unmerged revisions

35. By Mathieu Comandon on 2010-01-20

Fixed retrieval of images from icanhaz and failblog + made Gwibber an option

Preview Diff

1=== modified file 'bin/lolz'
2--- bin/lolz 2009-09-12 18:11:10 +0000
3+++ bin/lolz 2010-01-23 21:09:13 +0000
4@@ -19,22 +19,27 @@
5 import os
6 import gtk
7 import urllib
8+import urllib2
9 import datetime
10 import random
11 import dbus
12 import time
13+import logging
14+import re
15
16-#check if gwibber support is installed
17+#check if gwibber is wanted and if support is installed
18+gwibber_want = False
19 gwibber_support = False
20-try:
21- import gwibber.config
22- import gwibber.server
23-
24- gwibber_support = True
25-
26-except Exception, inst:
27- logging.debug("Failed to setup dbus connection to gwibber")
28- gwibber_support = False
29+if gwibber_want:
30+ try:
31+ import gwibber.config
32+ import gwibber.server
33+
34+ gwibber_support = True
35+
36+ except ImportError, inst:
37+ logging.debug("Failed to setup dbus connection to gwibber")
38+ gwibber_support = False
39
40
41 # Check if we are working in the source tree or from the installed
42@@ -48,7 +53,9 @@
43 fullPath = os.getcwd()
44 sys.path.insert(0, os.path.dirname(fullPath))
45
46-from lolz import AboutLolzDialog, PreferencesLolzDialog, MicroblogDialog
47+from lolz import AboutLolzDialog, PreferencesLolzDialog
48+if gwibber_support:
49+ from lolz import MicroblogDialog
50 from lolz.lolzconfig import getdatapath
51 from lolz.AsynchTaskProgressBox import AsynchTaskProgressBox
52
53@@ -129,7 +136,7 @@
54 logging.debug('day_selected() called')
55 self.calendar.hide()
56 d = self.calendar.get_date()
57- display_date = datetime.date(d[0],d[1],d[2])
58+ display_date = datetime.date(d[0],d[1]+1,d[2])
59 self.builder.get_object("calendar_button").set_label(display_date.isoformat())
60
61 #clear out the curren set of images
62@@ -251,19 +258,16 @@
63
64
65 def __get_fail_images(date):
66+ """
67+ example url : <img class="mine_3010416640" title="epic-fail-prison-guard-fail" src="http://failblog.files.wordpress.com/2009/12/epic-fail-prison-guard-fail.jpg" alt="epic fail pictures" />
68+ """
69 html = __get_html_for_date("http://failblog.org/",date)
70-
71- mines = html.split("mine_")
72- del(mines[0])
73 images = []
74- for m in mines:
75- if m.find("imageid_") > -1:
76- pz = m.split("<img src=\"")
77- url = pz[1].split("\" alt=")[0]
78- if url.find("?") > -1:
79- url = url.split("?")[0]
80- images.append(__download_image(url,"http://failblog.org/","source: failblog.org"))
81-
82+ fail_re = "[\"\'](http://failblog.files.wordpress.com.*?jpg)[\"\']"
83+ pics = re.findall(fail_re,html,re.MULTILINE | re.IGNORECASE)
84+ for pic in pics:
85+ logging.debug(pic)
86+ images.append(__download_image(pic,"http://failblog.org/","source: failblog.org"))
87 logging.debug('found fail images:')
88 logging.debug(images)
89
90@@ -272,44 +276,34 @@
91
92 def __get_hotdog_images(date):
93 html = __get_html_for_date("http://ihasahotdog.com/",date)
94-
95- mines = html.split("mine_")
96- del(mines[0])
97+ fail_re = "[\"\'](http://ihasahotdog.files.wordpress.com.*?jpg)[\"\']"
98+ pics = re.findall(fail_re,html,re.MULTILINE | re.IGNORECASE)
99 images = []
100- for m in mines:
101- if m.find("src") > -1 and m.find("Add this to your blog") == -1:
102- if m.find("src=\"") > -1:
103- pz = m.split("src=\"")
104- if pz[1].find("LJT") == -1 and pz[1].find("imagestore") == -1:
105- url = pz[1].split("?")[0]
106- url = url.split("\" alt")[0]
107- images.append(__download_image(url,"http://ihasahotdog.com/","source: ihasahotdog.com"))
108+ for pic in pics:
109+ images.append(__download_image(pic,"http://ihasahotdog.com/","source: ihasahotdog.com"))
110 logging.debug('found hotdog images:')
111 logging.debug(images)
112 return images
113
114 def __get_html_for_date(url, date):
115 logging.debug('getting html from ' + url + ' for ' + str(date))
116- dt_suffix = str(date.year) + "/" + str(date.month + 1) + "/" + str(date.day)
117+ dt_suffix = str(date.year) + "/" + str(date.month) + "/" + str(date.day)
118 day_url = url + dt_suffix
119- f = urllib.urlopen(day_url)
120- html = f.read()
121+ logging.debug(day_url)
122+ user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20100106 Ubuntu/10.04 (lucid) Firefox/3.5.7"
123+ headers = { 'User-agent' : user_agent }
124+ request = urllib2.Request(day_url,None,headers)
125+ request_content = urllib2.urlopen(request)
126+ html = request_content.read()
127 return html
128
129 def __get_cheez_images(date):
130 html = __get_html_for_date("http://icanhascheezburger.com/",date)
131-
132- mines = html.split("mine_")
133- if len(mines) < 2:
134- return []
135- del(mines[0])
136- del(mines[1])
137 images = []
138- for m in mines:
139- if m.find("src") > -1 and m.find("Add this to your blog") == -1:
140- pz = m.split("src")
141- url = pz[1].split("&quot;")[1]
142- images.append(__download_image(url, "http://icanhascheezburger.com/", "source: icanhascheezburger.com"))
143+ pics_re = "\<img.*?(http://icanhascheezburger.files.wordpress.com.*?.jpg)\" alt=\"funny pictures of cats with captions.*?\>"
144+ pics = re.findall(pics_re,html,re.MULTILINE | re.IGNORECASE | re.DOTALL)
145+ for pic in pics:
146+ images.append(__download_image(pic, pic, "source: icanhascheezburger.com"))
147 logging.debug('found cheezburger images:')
148 logging.debug(images)
149 return images
150@@ -323,7 +317,9 @@
151 os.makedirs(lolz_cache)
152 fname = os.path.join(lolz_cache,fname)
153 if not os.path.exists(fname):
154- img_stream = urllib.urlopen(url)
155+ headers = { 'User-agent' : "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20100106 Ubuntu/10.04 (lucid) Firefox/3.5.7" }
156+ request = urllib2.Request(url,None,headers)
157+ img_stream = urllib2.urlopen(request)
158 img_file = open(fname,'w')
159 img_file.write(img_stream.read())
160 img_file.flush()
161
162=== modified file 'data/ui/LolzWindow.ui'
163--- data/ui/LolzWindow.ui 2009-09-12 18:11:10 +0000
164+++ data/ui/LolzWindow.ui 2010-01-23 21:09:13 +0000
165@@ -27,50 +27,11 @@
166 <object class="GtkMenu" id="menu1">
167 <property name="visible">True</property>
168 <child>
169- <object class="GtkImageMenuItem" id="imagemenuitem1">
170- <property name="label">gtk-new</property>
171- <property name="visible">True</property>
172- <property name="use_action_appearance">True</property>
173- <property name="use_underline">True</property>
174- <property name="use_stock">True</property>
175- <accelerator key="n" signal="activate" modifiers="GDK_CONTROL_MASK"/>
176- </object>
177- </child>
178- <child>
179- <object class="GtkImageMenuItem" id="imagemenuitem2">
180- <property name="label">gtk-open</property>
181- <property name="visible">True</property>
182- <property name="use_underline">True</property>
183- <property name="use_stock">True</property>
184- </object>
185- </child>
186- <child>
187- <object class="GtkImageMenuItem" id="imagemenuitem3">
188- <property name="label">gtk-save</property>
189- <property name="visible">True</property>
190- <property name="use_underline">True</property>
191- <property name="use_stock">True</property>
192- </object>
193- </child>
194- <child>
195- <object class="GtkImageMenuItem" id="imagemenuitem4">
196- <property name="label">gtk-save-as</property>
197- <property name="visible">True</property>
198- <property name="use_underline">True</property>
199- <property name="use_stock">True</property>
200- </object>
201- </child>
202- <child>
203- <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
204- <property name="visible">True</property>
205- </object>
206- </child>
207- <child>
208 <object class="GtkImageMenuItem" id="imagemenuitem5">
209- <property name="label">gtk-quit</property>
210+ <property name="label">'kthxbye</property>
211 <property name="visible">True</property>
212- <property name="use_underline">True</property>
213- <property name="use_stock">True</property>
214+ <property name="image">image1</property>
215+ <property name="use_stock">False</property>
216 <signal name="activate" handler="quit"/>
217 </object>
218 </child>
219@@ -87,43 +48,6 @@
220 <object class="GtkMenu" id="menu2">
221 <property name="visible">True</property>
222 <child>
223- <object class="GtkImageMenuItem" id="imagemenuitem6">
224- <property name="label">gtk-cut</property>
225- <property name="visible">True</property>
226- <property name="use_underline">True</property>
227- <property name="use_stock">True</property>
228- </object>
229- </child>
230- <child>
231- <object class="GtkImageMenuItem" id="imagemenuitem7">
232- <property name="label">gtk-copy</property>
233- <property name="visible">True</property>
234- <property name="use_underline">True</property>
235- <property name="use_stock">True</property>
236- </object>
237- </child>
238- <child>
239- <object class="GtkImageMenuItem" id="imagemenuitem8">
240- <property name="label">gtk-paste</property>
241- <property name="visible">True</property>
242- <property name="use_underline">True</property>
243- <property name="use_stock">True</property>
244- </object>
245- </child>
246- <child>
247- <object class="GtkImageMenuItem" id="imagemenuitem9">
248- <property name="label">gtk-delete</property>
249- <property name="visible">True</property>
250- <property name="use_underline">True</property>
251- <property name="use_stock">True</property>
252- </object>
253- </child>
254- <child>
255- <object class="GtkSeparatorMenuItem" id="separatormenuitem2">
256- <property name="visible">True</property>
257- </object>
258- </child>
259- <child>
260 <object class="GtkImageMenuItem" id="imagemenuitem11">
261 <property name="label">gtk-preferences</property>
262 <property name="visible">True</property>
263@@ -137,13 +61,6 @@
264 </object>
265 </child>
266 <child>
267- <object class="GtkMenuItem" id="menuitem3">
268- <property name="visible">True</property>
269- <property name="label" translatable="yes">_View</property>
270- <property name="use_underline">True</property>
271- </object>
272- </child>
273- <child>
274 <object class="GtkMenuItem" id="menuitem4">
275 <property name="visible">True</property>
276 <property name="label" translatable="yes">_Help</property>
277@@ -268,4 +185,8 @@
278 </object>
279 </child>
280 </object>
281+ <object class="GtkImage" id="image1">
282+ <property name="visible">True</property>
283+ <property name="stock">gtk-missing-image</property>
284+ </object>
285 </interface>
286
287=== modified file 'debian/changelog'
288--- debian/changelog 2009-09-14 16:02:03 +0000
289+++ debian/changelog 2010-01-23 21:09:13 +0000
290@@ -1,3 +1,9 @@
291+lolz (1.238~public1) lucid; urgency=low
292+
293+ * New release.
294+
295+ -- Mathieu Comandon <strycore@gmail.com> Wed, 20 Jan 2010 22:34:30 +0100
296+
297 lolz (1.138) karmic; urgency=low
298
299 * New release.
300
301=== modified file 'debian/control'
302--- debian/control 2009-09-10 19:17:03 +0000
303+++ debian/control 2010-01-23 21:09:13 +0000
304@@ -16,7 +16,7 @@
305 Depends: ${misc:Depends},
306 ${python:Depends},
307 python-dbus,
308- python-desktopcouch,
309- python-gtk2
310+ python-gtk2,
311+ python-desktopcouch-records
312 Description: I can has lolz
313 The least essential application ever
314
315=== modified file 'lolz/PreferencesLolzDialog.py'
316--- lolz/PreferencesLolzDialog.py 2009-09-12 18:11:10 +0000
317+++ lolz/PreferencesLolzDialog.py 2010-01-23 21:09:13 +0000
318@@ -17,6 +17,7 @@
319 import sys
320 import os
321 import gtk
322+
323 from desktopcouch.records.server import CouchDatabase
324 from desktopcouch.records.record import Record
325
326
327=== modified file 'setup.py'
328--- setup.py 2009-09-19 16:38:02 +0000
329+++ setup.py 2010-01-23 21:09:13 +0000
330@@ -93,10 +93,10 @@
331
332 DistUtilsExtra.auto.setup(
333 name='lolz',
334- version='1.238',
335+ version='1.238~public1',
336 license='GPL v3',
337- author='Rick Spencer',
338- author_email='rick.spencer@canonical.com',
339+ author='Mathieu Comandon',
340+ author_email='strycore@gmail.com',
341 description='I can has lolz',
342 long_description='The least essential application ever',
343 url='https://launchpad.net/lolz',

Subscribers

People subscribed via source and target branches

to all changes: