Example #1
0
def loadSynonyms():
    try:

        with fm.readFile("cargue_ontologia.txt", fm.path['loads']) as file:

            def function(redisClient):
                for line in file:
                    ajson = json.loads(line)
                    for key in ajson:
                        for key_2 in ajson[key]:
                            for item in ajson[key][key_2]:
                                print "set " + "CLAVE=" + "sinonimo:" + item.encode(
                                    'utf-8') + "  VALOR=" + key.encode(
                                        'utf-8') + ":" + key_2.encode('utf-8')
                                print "Registros insertados: " + str(
                                    redisClient.set(
                                        "sinonimo:" + item.encode('utf-8'),
                                        key.encode('utf-8') + ":" +
                                        key_2.encode('utf-8')))
                        print

            redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError("No se puede leer el archivo: \n" + str(ierror))
    except Exception as ex:
        fm.registerError("Se presento el error en la carga de sinonimos: \n" +
                         str(ex))
Example #2
0
def test_message(message):
    try:
        emit('my response', politic_scrapeTable(message))
    except Exception as e:
        fm.registerError("Error en el scraper del personaje: " + str(error))
    else:
        pass
    finally:
        pass
Example #3
0
def politic_scrapeTable(url):
    soup = getSoup(url)
    table = soup.find('table', 'infobox')
    table = getTable(soup)
    dic = {}
    try:
        if soup is not None:
            dic = jsonp.addValue(
                dic, "Fecha de registro",
                time.strftime("%x") + " " + time.strftime("%X"))
            dic = jsonp.addValue(
                dic, "Nombre",
                getTitle(soup).replace(' - Wikipedia, la enciclopedia libre',
                                       ''))
            dic = jsonp.addValue(dic, "Url", url)
            dic = jsonp.addValue(dic, "Imagen", getTableImage(url))
            filas = table.find_all('tr')[2:]
            dic["laboral - links"] = []
            parent = ""
            for fil in filas:
                if len(fil.find_all('th')) > 0 and len(fil.find_all('td')) < 1:
                    parent = jsonp.eliminateCharacters(
                        jsonp.clearValue(fil.find_all('th')[0].text))
                    dic["laboral - links"].append(
                        getLinks(fil.find_all('th')[0]))
                    dic = jsonp.addValue(dic, parent, {})
                elif len(fil.find_all('th')) > 0 and len(
                        fil.find_all('td')) > 0:
                    if parent != "":
                        dic[parent] = jsonp.addValue(
                            dic[parent],
                            fil.find_all('th')[0].text,
                            jsonp.clearValue(fil.find_all('td')[0].text))
                        if len(fil.find_all('td')[0].findAll('a')) > 0:
                            dic[parent] = jsonp.addValue(
                                dic[parent],
                                fil.find_all('th')[0].text + " - links",
                                getLinks(fil.find_all('td')[0]))
                    else:
                        dic = jsonp.addValue(dic,
                                             fil.find_all('th')[0].text,
                                             fil.find_all('td')[0].text)
    except Exception as error:
        fm.registerError(str(error))
    return dic
Example #4
0
def loadCategories():
    try:
        with fm.readFile("categorias.json") as file:
            for line in file:
                ajson = json.loads(line)
                print "sadd categoria " + ajson["category"].encode("utf-8")

                def function(redisClient):
                    return "Registros insertados: " + str(
                        redisClient.sadd(
                            "categoria",
                            u"Categor\u00eda:" + ajson["category"]))

                print(redis.sendRedis(function))
    except IOError as ierror:
        fm.registerError("No se puede leer el archivo: \n" + str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la carga de las categorias: \n" + str(ex))
Example #5
0
def loadStructureSite():
    try:
        structureJSON = fm.readJSONFile("siteStructure.json", fm.path['loads'])

        def function(redisClient):
            for prop in structureJSON:
                print "sadd site_node" + " -> " + prop.encode('utf-8')
                print "Registros insertados: " + str(
                    redisClient.sadd("site_node", prop.encode('utf-8')))

        redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError(
            "No se puede leer el archivo de estructura de sitios: \n" +
            str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la cargar la estructura de los sitios: \n"
            + str(ex))
Example #6
0
def loadOntology():
    try:
        ontyJSON = fm.readJSONFile("ontology.json", fm.path['loads'])

        def function(redisClient):
            for clase_nodo in ontyJSON['nodes']:
                for prop in ontyJSON['nodes'][clase_nodo]:
                    print "sadd node " + clase_nodo.encode(
                        'utf-8') + " -> " + prop.encode('utf-8')
                    print "Registros insertados: " + str(
                        redisClient.sadd("node:" + clase_nodo.encode('utf-8'),
                                         prop.encode('utf-8')))

        redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError("No se puede leer el archivo: \n" + str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la carga de la ontologia: \n" + str(ex))
Example #7
0
def loadAsociation():
    try:
        entities = fm.readJSONFile("entities.json", fm.path['loads'])

        def function(redisClient):
            for clase_nodo in entities:
                print "set CLAVE= entity:" + clase_nodo.encode(
                    'utf-8') + " VALOR= " + entities[clase_nodo].encode(
                        'utf-8')
                print "Registros insertados: " + str(
                    redisClient.set("entity:" + clase_nodo.encode('utf-8'),
                                    entities[clase_nodo].encode('utf-8')))

        redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError("No se puede leer el archivo: \n" + str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la carga de las entidades: \n" + str(ex))
Example #8
0
def recorrerGranEstructra():
    try:
        structureJSON = fm.readJSONFile("generalStructure.json",
                                        fm.path['loads'])

        def function(redisClient):
            for prop in structureJSON:
                for item in structureJSON[prop]:
                    if isinstance(structureJSON[prop][item], dict):
                        for key in structureJSON[prop][item]:
                            for key_2 in structureJSON[prop][item][key]:
                                print "hset noderel_" + prop.encode(
                                    'utf-8') + "_" + key.encode(
                                        'utf-8') + " " + key_2 + " " + str(
                                            structureJSON[prop][item][key]
                                            [key_2])
                                print "Registros insertados: " + str(
                                    redisClient.hset(
                                        "noderel_" + prop.encode('utf-8') +
                                        "_" + key.encode('utf-8'), key_2,
                                        str(structureJSON[prop][item][key]
                                            [key_2])))
                    else:
                        print "hset node_" + prop.encode(
                            'utf-8') + " " + item.encode(
                                'utf-8') + " " + structureJSON[prop][item]
                        print "Registros insertados: " + str(
                            redisClient.hset(
                                "node_" + prop.encode('utf-8'),
                                item.encode('utf-8'),
                                structureJSON[prop][item].encode('utf8')))

        redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError(
            "No se puede leer el archivo de estructura de instuciones: \n" +
            str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la cargar la estructura de los instuciones: \n"
            + str(ex))
Example #9
0
def loadParty():
    try:
        with fm.readFile("partys.json", fm.path['loads']) as partys:

            def function(redisClient):
                for party in partys:
                    jparty = json.loads(party)
                    print "set CLAVE= party:" + jparty["Url"].encode(
                        'utf-8') + " VALOR= " + jparty["Name"].encode('utf-8')
                    print "Registros insertados: " + str(
                        redisClient.set(
                            "party:" + jparty["Url"].encode('utf-8'),
                            jparty["Name"].encode('utf-8')))

            redis.sendRedis(function)
    except IOError as ierror:
        fm.registerError(
            "No se puede leer el archivo para la carga de partidos: \n" +
            str(ierror))
    except Exception as ex:
        fm.registerError(
            "Se presento el error en la carga de los partidos: \n" + str(ex))
Example #10
0
def politic_scrapeTable(url):
    soup = getSoup(url)
    table = soup.find('table', 'infobox')
    table = getTable(soup)
    dic = {}
    try:
        if soup is not None:
            dic = jsonp.addValue(
                dic, "Fecha de registro",
                time.strftime("%x") + " " + time.strftime("%X"))
            dic = jsonp.addValue(
                dic, "Nombre",
                getTitle(soup).replace(' - Wikipedia, la enciclopedia libre',
                                       ''))
            dic = jsonp.addValue(dic, "Url", url)
            dic = jsonp.addValue(dic, "Imagen", getTableImage(url))
            if table is not None:
                filas = table.find_all('tr')[1:] if dic[
                    'Imagen'] == "no disponible" else table.find_all('tr')[2:]
                dic["laboral"] = []
                for fil in filas:
                    if len(fil.find_all('th')) > 0 and len(
                            fil.find_all('td')) < 1:
                        parent = jsonp.eliminateCharacters(
                            jsonp.clearValue(fil.find_all('th')[0].text))
                        for link in getLinks(fil.find_all('th')[0]):
                            dic["laboral"].append(link)
                        dic = jsonp.addValue(dic, parent, {})
                    elif len(fil.find_all('th')) > 0 and len(
                            fil.find_all('td')) > 0:
                        if parent != "":
                            data_clean = jsonp.clearValue(''.join(
                                value for value in fil.find_all(text=True)
                                if value.parent.name != 'a'
                                and value.parent.name != 'th' and value != ''
                                and value != ' ' and value != '\n'))
                            if hasattr(data_clean, '__iter__'):
                                if len(data_clean) > 0:
                                    dic[parent] = jsonp.addValue(
                                        dic[parent],
                                        fil.find_all('th')[0].text,
                                        [{
                                            'title':
                                            jsonp.eliminateCharacters_title(
                                                text),
                                            'url':
                                            None
                                        } for text in data_clean
                                         if text != '' and text != ''])
                            elif data_clean != '':
                                dic[parent] = jsonp.addValue(
                                    dic[parent],
                                    fil.find_all('th')[0].text, [{
                                        'title':
                                        jsonp.eliminateCharacters_title(
                                            data_clean),
                                        'url':
                                        None
                                    }])
                            if len(fil.find_all('td')[0].findAll('a')) > 0:
                                if dic[parent].has_key(
                                        jsonp.eliminateCharacters(
                                            fil.find_all('th')[0].text)):
                                    for link in getLinks(
                                            fil.find_all('td')[0]):
                                        if link.get('url'):
                                            dic[parent][fil.find_all('th')
                                                        [0].text].append(link)
                                else:
                                    dic[parent] = jsonp.addValue(
                                        dic[parent],
                                        fil.find_all('th')[0].text,
                                        getLinks(fil.find_all('td')[0]))
                        else:
                            dic = jsonp.addValue(dic,
                                                 fil.find_all('th')[0].text,
                                                 fil.find_all('td')[0].text)
            dic = jsonp.addValue(dic, 'content', getContent(url))
    except Exception as error:
        fm.registerError(url + "\n" + str(error))
    return dic
Example #11
0
def politic_scrapeTable(url):
    soup = getSoup(url)
    table = soup.find('table', 'infobox')
    table = getTable(soup)
    dic = {}
    parent = 'default'
    dic = jsonp.addValue(dic, 'default', {})
    try:
        if soup is not None:
            dic = jsonp.addValue(
                dic, "Fecha de registro",
                time.strftime("%x") + " " + time.strftime("%X"))
            dic = jsonp.addValue(
                dic, "Nombre",
                getTitle(soup).replace(' - Wikipedia, la enciclopedia libre',
                                       ''))
            dic = jsonp.addValue(dic, "Url", url.strip())
            dic = jsonp.addValue(dic, "Imagen", getTableImage(url))
            cargo = None
            if table is not None:
                filas = table.find_all('tr')[1:] if dic[
                    'Imagen'] == "No disponible" else table.find_all('tr')[1:]
                for fil in filas:
                    if len(fil.find_all('th')) > 0:
                        if len(fil.find_all('td')) == 0:
                            parent = jsonp.eliminateCharacters(
                                jsonp.clearValue(fil.find_all('th')[0].text))
                            parent = jsonp.eliminateCharacters(parent)
                            dic = jsonp.addValue(dic, parent, {})
                            cargo = fil.find_all('th')[0]
                        else:
                            if parent != "":
                                data_clean = jsonp.clearValue(''.join(
                                    value for value in fil.find_all(text=True)
                                    if value.parent.name != 'a' and
                                    value.parent.name != 'th' and value != ''
                                    and value != ' ' and value != '\n'))
                                if hasattr(data_clean,
                                           '__iter__') and len(data_clean) > 0:
                                    dic[parent] = jsonp.addValue(
                                        dic[parent],
                                        fil.find_all('th')[0].text,
                                        [{
                                            'title':
                                            jsonp.eliminateCharacters_title(
                                                text),
                                            'url':
                                            None
                                        } for text in data_clean
                                         if text != '' and text != ''])
                                elif data_clean != '':
                                    dic[parent] = jsonp.addValue(
                                        dic[parent],
                                        fil.find_all('th')[0].text, [{
                                            'title':
                                            jsonp.eliminateCharacters_title(
                                                data_clean),
                                            'url':
                                            None
                                        }])
                                if len(fil.find_all('td')[0].findAll('a')) > 0:
                                    if dic[parent].has_key(
                                            jsonp.eliminateCharacters(
                                                fil.find_all('th')[0].text)):
                                        for link in getLinks(
                                                fil.find_all('td')[0]):
                                            if link.get('url'):
                                                dic[parent][
                                                    jsonp.eliminateCharacters(
                                                        fil.find_all('th')
                                                        [0].text)].append(link)
                                    else:
                                        dic[parent] = jsonp.addValue(
                                            dic[parent],
                                            fil.find_all('th')[0].text,
                                            getLinks(fil.find_all('td')[0]))
                            else:
                                """if len(fil.find_all('td')[0].findAll('a'))>0:
									dic = jsonp.addValue(dic,fil.find_all('th')[0].text, getLinks(fil.find_all('td')[0]))
								else:"""
                                dic = jsonp.addValue(
                                    dic,
                                    fil.find_all('th')[0].text,
                                    fil.find_all('td')[0].text)
                    else:
                        if len(
                                fil.find_all('td')
                        ) > 0 and fil.find_all('td')[0].text.strip(
                        ) != "" and parent != "" and "Wikidata" not in fil.find_all(
                                'td')[0].text:
                            dic[parent] = jsonp.addValue(
                                dic[parent], 'Perido del cargo',
                                fil.find_all('td')[0].text)
                            if cargo != None:
                                dic[parent] = jsonp.addValue(
                                    dic[parent], 'Entidad', getLinks(cargo))
    except Exception as error:
        print str(eror)
        fm.registerError(url + "\n" + str(error))
    return dic