Commit eead56df90e804a19510cf35b51089ff9aebb3b4

Authored by kvik
Committed by selurvedu
1 parent 5d330857

Add funders functions

@@ -118,6 +118,31 @@ def get_document_by_id(data, doc_id): @@ -118,6 +118,31 @@ def get_document_by_id(data, doc_id):
118 raise Exception('Document with id {} not found'.format(doc_id)) 118 raise Exception('Document with id {} not found'.format(doc_id))
119 119
120 120
  121 +def get_tenders_by_funder_id(client,
  122 + funder_id=None,
  123 + descending=True,
  124 + tender_id_field='tenderID',
  125 + opt_fields=('funders',)):
  126 + params = {'offset': '',
  127 + 'opt_fields': ','.join((tender_id_field,) + opt_fields),
  128 + 'descending': descending}
  129 + tender_list = True
  130 + client._update_params(params)
  131 + tenders_with_funder = {}
  132 + while tender_list and not tenders_with_funder:
  133 + tender_list = client.get_tenders()
  134 + for tender in tender_list:
  135 + if 'funders' in tender:
  136 + tenders_with_funder[tender[tender_id_field]] = [el['identifier']['id'] for el in tender['funders']]
  137 + # In case we are looking for a specific funder
  138 + if funder_id:
  139 + tenders_with_funder = {k: v for k, v in tenders_with_funder.items() if funder_id in v}
  140 + if not tenders_with_funder:
  141 + raise IdNotFound
  142 + else:
  143 + return tenders_with_funder
  144 +
  145 +
121 def download_file_from_url(url, path_to_save_file): 146 def download_file_from_url(url, path_to_save_file):
122 f = open(path_to_save_file, 'wb') 147 f = open(path_to_save_file, 'wb')
123 f.write(urllib.urlopen(url).read()) 148 f.write(urllib.urlopen(url).read())
@@ -37,10 +37,18 @@ def create_fake_funder(): @@ -37,10 +37,18 @@ def create_fake_funder():
37 return fake.funders_data() 37 return fake.funders_data()
38 38
39 39
  40 +def get_fake_funder_scheme():
  41 + return fake.funder_scheme()
  42 +
  43 +
40 def create_fake_amount(award_amount): 44 def create_fake_amount(award_amount):
41 return round(random.uniform(1, award_amount), 2) 45 return round(random.uniform(1, award_amount), 2)
42 46
43 47
  48 +def create_fake_number(min_number, max_number):
  49 + return random.randint(int(min_number), int(max_number))
  50 +
  51 +
44 def create_fake_title(): 52 def create_fake_title():
45 return u"[ТЕСТУВАННЯ] {}".format(fake.title()) 53 return u"[ТЕСТУВАННЯ] {}".format(fake.title())
46 54
@@ -22,6 +22,7 @@ class OP_Provider(BaseProvider): @@ -22,6 +22,7 @@ class OP_Provider(BaseProvider):
22 word_list = _fake_data.words 22 word_list = _fake_data.words
23 procuringEntities = _fake_data.procuringEntities 23 procuringEntities = _fake_data.procuringEntities
24 funders = _fake_data.funders 24 funders = _fake_data.funders
  25 + funders_scheme_list = _fake_data.funders_scheme
25 addresses = _fake_data.addresses 26 addresses = _fake_data.addresses
26 classifications = _fake_data.classifications 27 classifications = _fake_data.classifications
27 cpvs = _fake_data.cpvs 28 cpvs = _fake_data.cpvs
@@ -95,6 +96,9 @@ class OP_Provider(BaseProvider): @@ -95,6 +96,9 @@ class OP_Provider(BaseProvider):
95 def funders_data(self): 96 def funders_data(self):
96 return self.random_element(self.funders) 97 return self.random_element(self.funders)
97 98
  99 + @classmethod
  100 + def funder_scheme(self):
  101 + return self.random_element(self.funders_scheme_list)
98 102
99 @classmethod 103 @classmethod
100 def cpv(self): 104 def cpv(self):
@@ -532,6 +532,130 @@ @@ -532,6 +532,130 @@
532 } 532 }
533 } 533 }
534 ], 534 ],
  535 + "funders_scheme": [
  536 + "AE-ACCI",
  537 + "AE-ADCD",
  538 + "AE-AFZ",
  539 + "AE-DCCI",
  540 + "AE-DFSA",
  541 + "AE-DIFC",
  542 + "AE-FFZ",
  543 + "AT-FN",
  544 + "AE-FUJCCI",
  545 + "AE-HFZA",
  546 + "AE-RAKIA",
  547 + "AE-SAIF",
  548 + "AE-SCCI",
  549 + "AE-UAQCCI",
  550 + "AF-CBR",
  551 + "AF-MOE",
  552 + "AU-ABN",
  553 + "AU-ACNC",
  554 + "BD-NAB",
  555 + "BE-BCE_KBO",
  556 + "BE-GTCF",
  557 + "BG-EIK",
  558 + "BY-UNP",
  559 + "CA-CRA_ACR",
  560 + "CH-ZEFIX",
  561 + "CN-SAIC",
  562 + "CO-CCB",
  563 + "CY-DRCOR",
  564 + "CZ-ICO",
  565 + "DE-CRP",
  566 + "DK-CVR",
  567 + "EE-RIK",
  568 + "ES-DIR3",
  569 + "ES-RMS",
  570 + "ET-MFA",
  571 + "FI-PRO",
  572 + "FR-INSEE",
  573 + "FR-RCS",
  574 + "GB-CHC",
  575 + "GB-COH",
  576 + "GB-EDU",
  577 + "GB-GOV",
  578 + "GB-GOVUK",
  579 + "GB-NIC",
  580 + "GB-REV",
  581 + "GB-SC",
  582 + "GB-UKPRN",
  583 + "GG-RCE",
  584 + "GH-DSW",
  585 + "HU-VAT",
  586 + "ID-KDN",
  587 + "ID-KHH",
  588 + "ID-KLN",
  589 + "ID-PRO",
  590 + "IE-CHY",
  591 + "IE-CRO",
  592 + "IL-ROC",
  593 + "IM-CR",
  594 + "IM-GR",
  595 + "IN-MCA",
  596 + "IT-RI",
  597 + "JE-CR",
  598 + "JE-OAC",
  599 + "JP-JCN",
  600 + "KE-NCB",
  601 + "KE-RCO",
  602 + "KE-RSO",
  603 + "KZ-BIN",
  604 + "LS-LCN",
  605 + "LT-PVM",
  606 + "LT-RC",
  607 + "LV-RE",
  608 + "MD-IDNO",
  609 + "MM-MHA",
  610 + "MW-CNM",
  611 + "MW-MRA",
  612 + "MW-NBM",
  613 + "MW-RG",
  614 + "MY-SSM",
  615 + "MZ-MOJ",
  616 + "NG-CAC",
  617 + "NL-KVK",
  618 + "NO-BRC",
  619 + "NP-CRO",
  620 + "NP-SWC",
  621 + "PK-PCP",
  622 + "PK-VSWA",
  623 + "PL-REGON",
  624 + "PL-NIP",
  625 + "PL-KRS",
  626 + "PT-NIPPC",
  627 + "RO-CUI",
  628 + "RS-APR",
  629 + "RU-INN",
  630 + "RU-OGRN",
  631 + "SE-BLV",
  632 + "SG-ACRA",
  633 + "SI-PRS",
  634 + "SI-TIN",
  635 + "SK-ZRSR",
  636 + "TR-MERSIS",
  637 + "TR-VAT",
  638 + "TZ-BRLA",
  639 + "UA-EDR",
  640 + "UG-NGB",
  641 + "UG-RSB",
  642 + "US-DOS",
  643 + "US-EIN",
  644 + "US-USAGOV",
  645 + "UZ-KTUT",
  646 + "XI-IATI",
  647 + "XI-PB",
  648 + "XM-DAC",
  649 + "XM-EORI",
  650 + "XM-OCHA",
  651 + "ZA-CIP",
  652 + "ZA-NPO",
  653 + "ZA-PBO",
  654 + "ZM-NRB",
  655 + "ZM-PCR",
  656 + "ZW-PVO",
  657 + "ZW-ROD"
  658 + ],
535 "procuringEntities": [ 659 "procuringEntities": [
536 { 660 {
537 "contactPoint": { 661 "contactPoint": {
@@ -20,8 +20,10 @@ from .initial_data import ( @@ -20,8 +20,10 @@ from .initial_data import (
20 create_fake_doc, 20 create_fake_doc,
21 create_fake_sentence, 21 create_fake_sentence,
22 create_fake_amount, 22 create_fake_amount,
  23 + create_fake_number,
23 create_fake_date, 24 create_fake_date,
24 create_fake_funder, 25 create_fake_funder,
  26 + get_fake_funder_scheme,
25 fake, 27 fake,
26 subtraction, 28 subtraction,
27 field_with_id, 29 field_with_id,
Please register or login to post a comment