Example #1
0
    def Toolbar_TransmUrl(self, event): # wxGlade: MainFrame.<event_handler>
        page = self.SearchNotebook.GetCurrentPage()
        if page:
            selected = page.torrList.GetSelectedObject() 
            if selected and selected.url:
                config = self.ReadConfig()
                data = config['transmission']
                plugin_file = open('plugins/'+ selected.plugin + '.json','r')
                plugin = json.loads(plugin_file.read())
                plugin_file.close()

                if 'crawler' in plugin['url_filter']:
                    config = self.ReadConfig()
                    try:
                        url = crawler(selected.url,plugin['url_filter']['crawler'],plugin['headers'],config['timeout'])
                    except StandardError,msg:
                        self.ReportError("Can\'t establish a connection. Reason:"+str(msg))
                        return
                else:
                    url = selected.url

                if not self.tc:
                    try:
                        self.tc = transmissionrpc.Client(address=data['host'],port=data['port'],user=data['user'],password=data['pass'])
                    except transmissionrpc.TransmissionError,original:
                        msg = "Can\'t connect to Transmission client:" + str(original)
                        self.ReportError(msg)
                        return -1
                try:
                    data = doRequest(url,plugin['headers'],config['timeout'])
                    self.NewTorr(data.read())
                except StandardError,msg:
                    self.ReportError('Can\'t download torrent from site. Reason:' + str(msg))
Example #2
0
 def revisor(self, lugar):
     """Parametros:
     recibe un string de la ciudad a buscar.
     
     Variables:
         ciudades: diccionario usado para almacenar las ciudades buscadas 
                 previamente en la API.
     Regresa:
         Cadena con los datos de clima, temperatura minima y maxima
         y su % de humedad
     """
     ciudades = {}
     if lugar in ciudades:
         print(ciudades)
         return ciudades[lugar]
     else:
         iata = filtro.revisa(self, lugar)
         datos = doRequest(iata)
         ciudades[lugar] = datos
         print(ciudades)
         return ciudades[lugar]
Example #3
0
    def __kayak(self,query,category,plugin,pages,timeout,plugin_name):

        page_counter = 0

        data = {}
        for op in plugin['operations']:
            data[op] = []

        for page_no in range(plugin["page_rules"]["start"], pages * plugin["page_rules"]["step"] + 1, plugin["page_rules"]["step"]):

            elements_counter = -1

            page_counter += 1

            if page_counter > pages:
                break

            urldata = plugin["pattern"].replace('[query]', quote_plus(query)).replace('[category]', str(category)).replace('[page]', str(page_no))
            wx.CallAfter(pub.sendMessage, "status", status="[" + plugin_name + "] Retrieving data on page " + str(page_counter))
            if PRINTURL:
                print("Fetched data on " + plugin['base_search_url'] + urldata)
            page = doRequest(plugin['base_search_url'] + urldata,plugin['headers'],timeout)
            wx.CallAfter(pub.sendMessage, "status", status="[" + plugin_name + "] Parsing data on page " + str(page_counter))
            soup = bs4.BeautifulSoup(page)
            del page


            output = {}   

            for op in plugin['operations']:

                if "fixed_value" in plugin[op]:
                        output[op] = [plugin[op]["fixed_value"]]*plugin["page_rules"]["max_items"]
                        continue

                output[op] = [] 

                for i in soup.findAll(plugin[op]['tag'], attrs=plugin[op]['attrs']):

                    if "attrs_len" in plugin[op] and len(i.attrs) != plugin[op]["attrs_len"]:
                            continue

                    if plugin[op]['method'] == 'text':
                        if "decode" in plugin[op]:
                            output[op].append(re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff]', '', i.text))
                        else:
                            output[op].append(i.text)
                    elif plugin[op]['method'] == 'attr':
                        output[op].append(i[plugin[op]["attr"]])

                if "chipper" in plugin[op]:
                    output[op] = output[op][plugin[op]["chipper"]["start"]:]
                    pos = 0
                    for i,val in  enumerate(output[op]):
                        if i%plugin[op]["chipper"]["step"] == 0:
                            output[op][pos] = val
                            pos+=1
                    output[op] = output[op][:min(pos,plugin["page_rules"]["max_items"])]

                if "manipulate" in plugin[op]:
                    for i,item in enumerate(output[op]):
                        if "regexp" in plugin[op]["manipulate"]: 
                            try:
                                output[op][i] = re.findall(plugin[op]["manipulate"]["regexp"], item)[0]
                            except StandardError, rex:
                                if DEBUG:
                                    wx.CallAfter(pub.sendMessage,"error",msg="Regexping error on "+ plugin_name + ": " + str(rex))
                                    print("Error while regexping(manipulate)[" + op+ "] " + item)
                                output[op][i] = ''

                        if "to_replace" in plugin[op]["manipulate"]:
                            for j,toReplace in enumerate(plugin[op]["manipulate"]["to_replace"]):
                                output[op][i] = output[op][i].replace(toReplace, plugin[op]["manipulate"]["replace_with"][j])
                        
                        if "prefix" in plugin[op]["manipulate"]:
                            output[op][i] = plugin[op]["manipulate"]["prefix"] + output[op][i]

                        if "suffix" in plugin[op]["manipulate"]:
                            output[op][i] += plugin[op]["manipulate"]["suffix"]


                if len(output[op]) < elements_counter or elements_counter < 0:
                    elements_counter = len(output[op])
                

            if SAFE:
                for key in output.keys():
                    output[key] = output[key][:elements_counter]

            if DEBUG:
                print("--------DUMP-----------")
                for key in output:
                    print("-------------[" + str(key) + "]")
                    print(str(output[key]))
                    print("-------------[" + str(len(output[key])) + "]")

            for op in plugin['operations']:
                data[op].extend(output[op])

            if len(output["titles_filter"]) < plugin["page_rules"]["max_items"]:
                break
Example #4
0
 def test_ciudad_minusculas(self):
     ciudad = "singapore"
     self.assertNotEqual(doRequest(ciudad), ", Ciudad inválida")
     print(doRequest(ciudad))
Example #5
0
 def test_ciudad_mayusculas(self):
     ciudad = "CHICAGO"
     self.assertNotEqual(doRequest(ciudad), ", Ciudad inválida")
     print(doRequest(ciudad))
Example #6
0
 def test_ciudad_valida(self):
     ciudad = "México"
     self.assertNotEqual(doRequest(ciudad), ", Ciudad inválida")
     print(doRequest(ciudad))
Example #7
0
 def test_ciudad_invalida(self):
     ciudad = "ciudad X"
     self.assertEqual(doRequest(ciudad), ", Ciudad inválida")
     print(doRequest(ciudad))