Package screenlets :: Package plugins :: Module Flickr
[hide private]
[frames] | no frames]

Source Code for Module screenlets.plugins.Flickr

 1  # 
 2  # Flickr module by Helder Fraga aka whise <helder.fraga@hotmail.com> 
 3  # 
 4  # This program is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation, either version 3 of the License, or 
 7  # (at your option) any later version. 
 8  #  
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  #  
14  # You should have received a copy of the GNU General Public License 
15  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
16   
17  from urllib import urlopen 
18  import Proxy 
19   
20 -class Flickr(object):
21 22 url_list = {} 23 24
25 - def __init__(self):
26 pass
27
28 - def get_image_list(self,url):
29 """Returns a Tuple containing images links and webpage links of a flickr url""" 30 list_a = [] 31 self.url_list = {} 32 proxies = Proxy.Proxy().get_proxy() 33 sourcetxt = urlopen(url,proxies=proxies).read() 34 while sourcetxt.find("Photo" + chr(34)) != -1: 35 image = sourcetxt[sourcetxt.find("Photo" + chr(34))+7:] 36 sourcetxt = image 37 sourceimage = image[image.find("a href=" + chr(34))+8:] 38 sourceimage = sourceimage[:sourceimage.find(chr(34)) ].strip() 39 realimage = image[image.find("mg src=" + chr(34))+8:] 40 realimage = realimage[:realimage.find(chr(34)) ].strip() 41 imageurl = 'http://www.flickr.com' + sourceimage 42 list_a.append(realimage) 43 self.url_list[realimage] = imageurl 44 return list_a
45 46
47 - def save_image(self,url,path):
48 """Saves the image from url in path""" 49 proxies = Proxy.Proxy().get_proxy() 50 sourcetxt = urlopen(url,proxies=proxies).read() 51 fileObj = open( path,"w") #// open for for write 52 fileObj.write(sourcetxt) 53 fileObj.close()
54