コード例 #1
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_raises_ares_server_error(self):
        company_id = 60159014
        responses.add(responses.GET, '{0}?ico={1}'.format(ARES_API_URL, company_id), match_querystring=True, body=_read_mock_response('server_fault.xml'))

        with self.assertRaises(AresServerError) as context:
            call_ares(company_id=company_id)

        self.assertEqual(context.exception.fault_code, u'Server.Service')
        self.assertEqual(context.exception.fault_message, u'obecná chyba serverové služby')
コード例 #2
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_raises_ares_server_error(self):
        company_id = 60159014
        responses.add(responses.GET,
                      '{0}?ico={1}'.format(ARES_API_URL, company_id),
                      match_querystring=True,
                      body=_read_mock_response('server_fault.xml'))

        with self.assertRaises(AresServerError) as context:
            call_ares(company_id=company_id)

        self.assertEqual(context.exception.fault_code, u'Server.Service')
        self.assertEqual(context.exception.fault_message,
                         u'obecná chyba serverové služby')
コード例 #3
0
def main():
    from ares_util.ares import call_ares

    with open('output.json', 'w') as output_file:
        ctu_company_id = "68407700"
        data = call_ares(ctu_company_id)
        output_file.write(json.dumps(data, indent=5))
コード例 #4
0
def getContactByIC(ic):

    contact = dbGetContactByIC(ic)
    if contact is None:
        ares = call_ares(ic)
        if ares:
            data = {
                'company': ares['legal']['company_name'],
                'ic': ares['legal']['company_id'],
                'dic': ares['legal']['company_vat_id'],
                'street': ares['address']['street'],
                'city': ares['address']['city'],
                'zip': ares['address']['zip_code'],
                'www': None,
                'email': None,
                'first_name': None,
                'last_name': None,
            }

            if ares['legal']['legal_form'] == '101':
                try:
                    split = ares['legal']['company_name'].split(' ')
                    data['first_name'] = split[0]
                    data['last_name'] = split[1]
                except Exception, e:
                    pass

            contact = dbAddContact(**data)
コード例 #5
0
ファイル: response_to_json.py プロジェクト: voda/ares_util
def main():
    from ares_util.ares import call_ares

    with open('output.json', 'w') as f:
        ctu_company_id = "68407700"
        data = call_ares(ctu_company_id)
        f.write(json.dumps(data, indent=5))
コード例 #6
0
ファイル: res_partner.py プロジェクト: yasserdjerbi/osoosh
    def _get_ares_data(self, company_registry):
        res = {}

        result = call_ares(company_registry)
        if not result:
            raise ValidationError(_("The partner is not listed on ARES Webservice."))

        company = result.get("legal")
        address = result.get("address")

        if company.get("company_vat_id"):
            res["vat"] = company.get("company_vat_id")

        if company.get("company_name"):
            res["name"] = company.get("company_name")

        if address.get("zip_code"):
            res["zip"] = address.get("zip_code")

        if address.get("street"):
            res["street"] = address.get("street")

        if address.get("city"):
            res["city"] = address.get("city")

        # Get country by country code
        # country = self.env['res.country'].search(
        #    [('code', 'ilike', vat_country)])
        # if country:
        #    res['country_id'] = country[0].id
        return res
コード例 #7
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_numerically_valid(self):
        company_id = 25596641
        responses.add(responses.GET,
                      '{0}?ico={1}'.format(ARES_API_URL, company_id),
                      match_querystring=True,
                      body=_read_mock_response('{}.xml'.format(company_id)))

        self.assertFalse(call_ares(company_id=company_id))
        self.assertEqual(1, len(responses.calls))
コード例 #8
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_encoding(self):
        company_id = 68407700
        responses.add(responses.GET, '{0}?ico={1}'.format(ARES_API_URL, company_id), match_querystring=True, body=_read_mock_response('{}.xml'.format(company_id)))

        ares_response = call_ares(company_id=company_id)

        self.assertEqual(ares_response['legal']['company_name'], "České vysoké učení technické v Praze")
        self.assertEqual(ares_response['address']['street'], "Zikova 1903/4")
        self.assertEqual(1, len(responses.calls))
コード例 #9
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_special_case_for_issue9(self):
        company_id = 25834151
        responses.add(responses.GET, '{0}?ico={1}'.format(ARES_API_URL, company_id), match_querystring=True, body=_read_mock_response('{}.xml'.format(company_id)))

        ares_response = call_ares(company_id=company_id)

        self.assertEqual(ares_response['legal']['company_name'], "HELLA AUTOTECHNIK NOVA, s.r.o.")
        self.assertEqual(ares_response['address']['street'], "Družstevní 338/16")
        self.assertEqual(ares_response['address']['city'], "Mohelnice")
        self.assertEqual(ares_response['address']['zip_code'], "78985")
        self.assertEqual(1, len(responses.calls))
コード例 #10
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_encoding(self):
        company_id = 68407700
        responses.add(responses.GET,
                      '{0}?ico={1}'.format(ARES_API_URL, company_id),
                      match_querystring=True,
                      body=_read_mock_response('{}.xml'.format(company_id)))

        ares_response = call_ares(company_id=company_id)

        self.assertEqual(ares_response['legal']['company_name'],
                         "České vysoké učení technické v Praze")
        self.assertEqual(ares_response['address']['street'], "Zikova 1903/4")
        self.assertEqual(1, len(responses.calls))
コード例 #11
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_valid_values(self):
        other_valid_company_ids = ('25063677', '1603094', '01603094', '27074358')

        for one_id in other_valid_company_ids:
            responses.add(responses.GET, '{0}?ico={1}'.format(ARES_API_URL, one_id), match_querystring=True, body=_read_mock_response('{}.xml'.format(one_id)))

        try:
            for one_id in other_valid_company_ids:
                ares_data = call_ares(company_id=one_id)
                self.assertEqual(normalize_company_id_length(one_id), ares_data['legal']['company_id'])
        except KeyError as error:
            self.fail(error)

        self.assertEqual(len(other_valid_company_ids), len(responses.calls))
コード例 #12
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_special_case_for_issue9(self):
        company_id = 25834151
        responses.add(responses.GET,
                      '{0}?ico={1}'.format(ARES_API_URL, company_id),
                      match_querystring=True,
                      body=_read_mock_response('{}.xml'.format(company_id)))

        ares_response = call_ares(company_id=company_id)

        self.assertEqual(ares_response['legal']['company_name'],
                         "HELLA AUTOTECHNIK NOVA, s.r.o.")
        self.assertEqual(ares_response['address']['street'],
                         "Družstevní 338/16")
        self.assertEqual(ares_response['address']['city'], "Mohelnice")
        self.assertEqual(ares_response['address']['zip_code'], "78985")
        self.assertEqual(1, len(responses.calls))
コード例 #13
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_valid_values(self):
        other_valid_company_ids = ('25063677', '1603094', '01603094',
                                   '27074358')

        for one_id in other_valid_company_ids:
            responses.add(responses.GET,
                          '{0}?ico={1}'.format(ARES_API_URL, one_id),
                          match_querystring=True,
                          body=_read_mock_response('{}.xml'.format(one_id)))

        try:
            for one_id in other_valid_company_ids:
                ares_data = call_ares(company_id=one_id)
                self.assertEqual(normalize_company_id_length(one_id),
                                 ares_data['legal']['company_id'])
        except KeyError as error:
            self.fail(error)

        self.assertEqual(len(other_valid_company_ids), len(responses.calls))
コード例 #14
0
ファイル: fakturuj.py プロジェクト: atx/fakturuj_pyco
def clean_invoice_data(data):
    """
    Overi ze data maji spravnou strukturu, doplni srajdy z aresu.
    """
    if not data.get('date'):
        data['date'] = datetime.today()
    else:
        try:
            data['date'] = date_parse(data['date'])
        except:
            fuckem('Zadal si blbe datum ve fakture. ')
    if not data['item_list']:
        fuckem('Musis vyplnit nejake polozky na fakturu...')
    data['date_due'] = data['date'] + timedelta(days=data['due_days'])

    if 'ico' not in data:
        assert 'company_data' in data, "You have to either specify ICO or company data."
        data['company_data']
    else:
        data['company_data'] = call_ares(data['ico'])
    return data
コード例 #15
0
    def handle(self, *args, **kwargs):
        # Stažení XML dat, kvůli veliksoti souboru používám stream=True
        url = 'https://rejstriky.msmt.cz/opendata/vrejcelk.xml'
        xml_response = requests.get(url=url, stream=True)
        # Parsne XMl data pro následnou manipulaci
        events = ElementTree.iterparse(xml_response.raw)

        # Data representujicí jednu školu
        data = {}

        # Projdeme každý element a uloží užitečná data
        for event, elem in events:

            if elem.tag == 'RedPlnyNazev':
                data['full_name'] = elem.text
            elif elem.tag == 'RedRUAINKod':
                data['ruian_code'] = elem.text
            elif elem.tag == 'RedAdresa1':
                data['address_1'] = elem.text
            elif elem.tag == 'RedAdresa2':
                data['address_2'] = elem.text
            elif elem.tag == 'RedAdresa3':
                data['address_3'] = elem.text
            elif elem.tag == 'ReditelJmeno':
                data['principal_name'] = elem.text
            elif elem.tag == 'ICO':
                data['company_id'] = elem.text
            elif elem.tag == 'PravniForma':
                data['legal_form'] = elem.text

            # PravniSubjekt je poslední tag, který každá škola má
            if elem.tag == 'PravniSubjekt':

                if kwargs['validate']:
                    # Validace IČO školy pomocí ares
                    ares_valid_data = call_ares(data['company_id'])
                else:
                    ares_valid_data = True

                if ares_valid_data:

                    if kwargs['validate']:
                        #Validace jména adresy školy pomocí ares
                        if not ares_valid_data['legal'][
                                'company_name'] == data['full_name']:
                            print(data['full_name'] + ' Is Not Valid')
                            continue
                        elif not ares_valid_data['legal'][
                                'legal_form'] == data['legal_form']:
                            print(data['legal_form'] + ' Is Not Valid')
                            continue
                        elif not ares_valid_data['address']['street'] == data[
                                'address_1']:
                            print(data['address_1'] + ' Is Not Valid')
                            continue

                    # Uloží Školu do DB
                    school = School(**data)
                    school.save()
                    print('SAVED')
                else:
                    print('************************')
                    print('FAILED')
                    print('************************')
                    continue

        print('***********************')
        print('Data Collected!')
        print('***********************')
コード例 #16
0
ファイル: server.py プロジェクト: zamazaljiri/ares_util
def ares_json_response(post_id):
    ares_response = call_ares(company_id=post_id)
    json_data = json.dumps(ares_response)

    return flask.Response(json_data, status=200, mimetype='application/json')
コード例 #17
0
ファイル: fakturuj.py プロジェクト: atx/fakturuj_pyco
def ask_stupid_questions():
    ico = input('ICO, pyco. ')
    personal_info = {'account': input('Cislo uctu: '), 'ares': call_ares(ico)}

    print('Diky, pyco.')
    return personal_info
コード例 #18
0
ファイル: ares_test.py プロジェクト: lichnak/ares_util
    def test_invalid_values(self):
        invalid_values = [False, True, 42, -42, "foo"]

        for invalid_value in invalid_values:
            self.assertFalse(call_ares(invalid_value))
コード例 #19
0
ファイル: playground.py プロジェクト: PaulRoss1/Formular
from ares_util.ares import call_ares


call_ares(42)
コード例 #20
0
def ares_json_response(post_id):
    ares_response = call_ares(company_id=post_id)
    json_data = json.dumps(ares_response)

    return flask.Response(json_data, status=200, mimetype='application/json')
コード例 #21
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_invalid_values(self):
        invalid_values = [False, True, 42, -42, "foo"]

        for invalid_value in invalid_values:
            self.assertFalse(call_ares(invalid_value))
コード例 #22
0
ファイル: ares_test.py プロジェクト: illagrenan/ares_util
    def test_numerically_valid(self):
        company_id = 25596641
        responses.add(responses.GET, '{0}?ico={1}'.format(ARES_API_URL, company_id), match_querystring=True, body=_read_mock_response('{}.xml'.format(company_id)))

        self.assertFalse(call_ares(company_id=company_id))
        self.assertEqual(1, len(responses.calls))