コード例 #1
0
def process_davivienda_message(message):
    print('Davivienda: processing message')
    amount = re.sub(r'[^\d.]', '', nth(lines(message.string), 6))
    category_type = nth(lines(message.string), 7)
    desc = trim(nth(split(nth(lines(message.string), 8), ':'), 1))
    if has_substr(upper_case(desc), 'PSE'):
        print('Davivienda: Ignored PSE payment')
        return None, None, None
    if has_substr(lower_case(category_type), 'deposito') or has_substr(
            lower_case(category_type), 'abono'):
        category_type = moneylover.CATEGORY_TYPE['income']
        category_item = 'Salary' if has_substr(
            upper_case(desc), 'ACH GNB SUDAMERIS') else 'Others'
    else:
        category_type = moneylover.CATEGORY_TYPE['expense']
        category_item = categorize(desc)
    return amount, {'type': category_type, 'item': category_item}, desc
コード例 #2
0
def predefined_category(text):
    if has_substr(lower_case(text), 'une'): return 'Bills & Utilities'
    if has_substr(lower_case(text), 'rappi'): return 'Food & Beverage'
    if has_substr(lower_case(text), 'comcel'): return 'Bills & Utilities'
    if has_substr(lower_case(text), 'nequi'): return 'Nequi'
    if has_substr(lower_case(text), 'credito visa'): return 'Credit Card'
    if has_substr(lower_case(text), 'fiducredicorp'): return 'Apartment'
    if has_substr(lower_case(text), 'canon'): return 'Rentals'
コード例 #3
0
def process_pse_message(message):
    print('PSE(davivienda): processing message')
    data = lines(last(message.table.table.find_all('span')))
    desc = re.sub(r'<[^<>]*>', '', nth(data))
    amount = re.sub(r'[^\d,]', '', nth(data, 1)).replace(',', '.')
    is_visa = has_substr(lower_case(desc), 'credito visa')
    if is_visa:
        visa_category_type = moneylover.CATEGORY_TYPE['income']
        visa_category_item = 'Payment'
    category_type = moneylover.CATEGORY_TYPE['expense']
    category_item = categorize(desc)
    return amount, {
        'type': category_type,
        'item': category_item
    }, desc, {
        'type': visa_category_type,
        'item': visa_category_item
    } if is_visa else None
コード例 #4
0
ファイル: test_strings.py プロジェクト: dgilland/pydash
def test_lower_case(case, expected):
    assert _.lower_case(case) == expected
コード例 #5
0
ファイル: extractor_core.py プロジェクト: mar71ns/ASSIN-UFV
def get_sinonimos(palavra):
    # print("-------------")
    # print(palavra)
    palavra = deburr(kebab_case(palavra))
    base_url = "https://www.sinonimos.com.br/"

    list_no_occur = get(nao_consta, "sinonimos")

    if has(sinonimos, palavra):
        #print("Palavra já consta no dicionário de sinônimos")
        return get(sinonimos, palavra)
    if palavra in list_no_occur:
        #print("Não foram encontrados sinônimos para a palavra")
        return []
    else:
        #print("\nNova Palavra: ", palavra)
        request_fail = True
        while request_fail:
            try:
                site = requests.get(base_url + palavra)
                request_fail = False
            except Exception as e:
                print(e)
                pass
        data = BeautifulSoup(site.content, 'html.parser')

        try:
            h1 = data.find('h1').getText()
        except Exception as e:
            if palavra is not None:
                list_no_occur = push(list_no_occur, palavra)
            set_(nao_consta, "sinonimos", list_no_occur)
            save_json("nao_consta", nao_consta)
            return []

        if (h1 == "Página Não Encontrada"):
            #print(h1)
            if palavra is not None:
                list_no_occur = push(list_no_occur, palavra)
            set_(nao_consta, "sinonimos", list_no_occur)
            save_json("nao_consta", nao_consta)
            return []
        else:
            content = data.find('div', attrs={'id': 'content'})
            try:
                div = content.findAll('div', attrs={'class': 's-wrapper'})
            except Exception as e:
                print(e)
                if palavra is not None:
                    list_no_occur = push(list_no_occur, palavra)
                set_(nao_consta, "sinonimos", list_no_occur)
                save_json("nao_consta", nao_consta)
                return []
            aux = 0
            for sentido in div:
                aux = aux + 1
                lista_sinonimos = []
                try:
                    try:
                        key = lower_case(
                            sentido.find('div', attrs={
                                'class': 'sentido'
                            }).getText().strip(":"))
                    except Exception as e:
                        print(e)
                        key = "sinonimos" + str(aux)
                        pass
                    values = sentido.findAll('a',
                                             attrs={'class': 'sinonimo'},
                                             text=True)
                    values2 = sentido.findAll('span')
                    # print(values2)
                    all_values = union(values, values2)
                    #print(all_values)
                    for value in all_values:
                        lista_sinonimos.append(value.getText().strip(":"))
                    set_(sinonimos, palavra + "." + key, lista_sinonimos)
                    print("Sinônimo Salv@ no Dicionário")
                except Exception as e:
                    print("\nError:\n" + str(e))
                    return []
            save_json("sinonimos", sinonimos)
            return get(sinonimos, palavra)
コード例 #6
0
ファイル: extractor_core.py プロジェクト: mar71ns/ASSIN-UFV
def get_antonimos(palavra):
    # print("-------------")
    # print(palavra)
    palavra = deburr(kebab_case(palavra))
    base_url = "https://www.antonimos.com.br/"

    list_no_occur = get(nao_consta, "antonimos")

    if has(antonimos, palavra):
        #print("Palavra já consta no dicionário de antônimos")
        return get(antonimos, palavra)
    if palavra in list_no_occur:
        #print("Não foram encontrados antônimos para a palavra")
        return []
    else:
        request_fail = True
        while request_fail:
            try:
                site = requests.get(base_url + palavra)
                request_fail = False
            except Exception as e:
                print(e)
                pass
        data = BeautifulSoup(site.content, 'html.parser')

        try:
            h1 = data.find('h1').getText()
        except Exception as e:
            if palavra is not None:
                list_no_occur = push(list_no_occur, palavra)
            set_(nao_consta, "antonimos", list_no_occur)
            save_json("nao_consta", nao_consta)
            return []
        if (h1 == "Página Não Encontrada"):
            #print(h1)
            if palavra is not None:
                list_no_occur = push(list_no_occur, palavra)
            set_(nao_consta, "antonimos", list_no_occur)
            save_json("nao_consta", nao_consta)
            return []
        else:
            content = data.find('div', attrs={'id': 'content'})
            try:
                div = content.findAll('div', attrs={'class': 's-wrapper'})
            except Exception as e:
                print(e)
                if palavra is not None:
                    list_no_occur = push(list_no_occur, palavra)
                set_(nao_consta, "antonimos", list_no_occur)
                save_json("nao_consta", nao_consta)
            aux = 0
            for sentido in div:
                aux = aux + 1
                lista_antonimos = []
                try:
                    try:
                        key = lower_case(
                            sentido.find('div', attrs={
                                'class': 'sentido'
                            }).getText().strip(":"))
                    except Exception as e:
                        key = lower_case(
                            sentido.find('strong').getText().strip("."))
                        pass
                    #print(sentido.find('p', attrs={'class':'antonimos'}))
                    p = sentido.find('p', attrs={
                        'class': 'antonimos'
                    }).getText()[3:]
                    try:
                        p = str(p.encode('raw_unicode_escape').decode('utf-8'))
                    except Exception as e:
                        print(e)
                        pass
                    #print(p)
                    #print(p.encode('utf-8'))
                    all_values = p.split(',')
                    #print(all_values)
                    for value in all_values:
                        lista_antonimos.append(value.strip(":").strip(' '))
                    set_(antonimos, palavra + "." + key, lista_antonimos)
                    print("Antônimo Salv@ no Dicionário")
                except Exception as e:
                    print("\nError:\n" + str(e))
                    return []
            save_json("antonimos", antonimos)
            return get(antonimos, palavra)