Commit 79fd32971110623dec580e4e93107dece5131326

Authored by smithumble
1 parent 4418b40e

Refactor client helper feed functions

... ... @@ -120,29 +120,25 @@ def get_document_by_id(data, doc_id):
120 120
121 121
122 122 def get_tenders_feed(client, interval=0.5):
123   - tender_list = True
124   - while tender_list:
125   - tender_list = client.get_tenders()
126   - for tender in tender_list:
127   - yield tender
128   - sleep(interval)
  123 + for item in get_items_feed(client, 'get_tenders', interval):
  124 + yield item
129 125
130 126
131 127 def get_plans_feed(client, interval=0.5):
132   - plans_list = True
133   - while plans_list:
134   - plans_list = client.get_plans()
135   - for plan in plans_list:
136   - yield plan
137   - sleep(interval)
  128 + for item in get_items_feed(client, 'get_plans', interval):
  129 + yield item
138 130
139 131
140 132 def get_contracts_feed(client, interval=0.5):
141   - plans_list = True
142   - while plans_list:
143   - plans_list = client.get_contracts()
144   - for plan in plans_list:
145   - yield plan
  133 + for item in get_items_feed(client, 'get_contracts', interval):
  134 + yield item
  135 +
  136 +def get_items_feed(client, client_method, interval=0.5):
  137 + items = True
  138 + while items:
  139 + items = getattr(client, client_method)()
  140 + for item in items:
  141 + yield item
146 142 sleep(interval)
147 143
148 144
... ...
Please register or login to post a comment