| Home | Trees | Indices | Help |
|---|
|
|
1 # -*- coding: cp1252 -*- 2 # 3 ################################################################################## 4 # 5 # This file is part of usufy.py. 6 # 7 # Usufy is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 ################################################################################## 21 22 import urllib2 23 import os 2426 """ 27 <Platform> abstract class. 28 """12830 """ 31 Constructor without parameters... 32 """ 33 #self.platformName = "Abstract Class" 34 # These tags will be the one used to label this platform 35 #self.tags = [] 36 # CONSTANT OF TEXT TO REPLACE 37 #self.NICK_WILDCARD = "HERE_GOES_THE_NICK" 38 # Usually it will contain a phrase like \"<HERE_GOES_THE_NICK>\" that will be the place where the nick will be included 39 #self.url = "http://test.com/" + self.NICK_WILDCARD 40 # Text to find when the user was NOT found 41 #self.notFoundText = [] 42 #self.score= 0.0 43 pass4446 """ 47 Private method that returns an URL for a given nick. 48 49 Return values: 50 string containing a URL 51 """ 52 return self.url.replace(self.NICK_WILDCARD, nick)5355 """ 56 Este método privado de la clase padre puede ser sobreescrito por cada clase hija si la verificación 57 a realizar es más compleja que la verificación estándar. 58 59 Valores retornados: 60 html Si el usuario en cuestión existe en esta red social. 61 None Si el usuario en cuestión no existe en esta red social. 62 """ 63 try: 64 recurso = urllib2.urlopen(url) 65 except : 66 # no se ha conseguido retornar una URL de perfil, por lo que se devuelve None 67 # print ">\tERROR: Something happened when trying to recover the resource..." 68 return None 69 html = recurso.read() 70 71 for t in self.notFoundText: 72 # si se encuentra el contenido en cuestión que confirma que el usuario no existe 73 if t in html: 74 # Returning that it does not exist 75 return None 76 return html7779 """ 80 Este método público es el que se encarga de recuperar la información de la página del usuario a buscar y de procesar si procede la descrga. 81 82 List of parameters used by this method: 83 nick: nick to search 84 outputF: will contain a valid path to the outputFolder 85 avoidProcessing:will define whether a further process is performed 86 87 Return values: 88 url URL del usuario en cuestión una vez que se haya confirmado su validez. 89 None En el caso de que no se haya podido obtener una URL válida. 90 """ 91 # generando la URL para el nick dado 92 url = self._genURL(nick) 93 # en función de la respuesta, se hace la comprobación de si el perfil existe o no 94 html = self._getResourceFromUser(url) 95 if html != None: 96 if not avoidProcessing: 97 # Storing file if the user has NOT said to avoid the process... 98 99 outputPath = os.path.join(outputF, nick) 100 if not os.path.exists(outputPath): 101 os.makedirs(outputPath) 102 self._processProfile(os.path.join(outputPath, nick + "_" + str(self).lower()), html) 103 return url 104 else: 105 # raise Exception, "UserNotFoundException: the user was not found in " + self.socialNetworkName 106 return None107109 """ 110 Method to process an URL depending on the functioning of the site. By default, it stores the html downloaded on a file. 111 This method might be overwritten by each and every class to perform different actions such as indexing the contents with tools like pysolr, for example. 112 113 Return values: 114 None 115 """ 116 with open (oP, "w") as oF: 117 oF.write(html) 118 return True119
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sun Jul 6 01:20:08 2014 | http://epydoc.sourceforge.net |