1818GEC_CODES = GECCode .objects .select_related ('country' ).all ()
1919APPEAL_DOCUMENT_TYPES = AppealDocumentType .objects .all () # used only for read in appealdocument locations from api
2020
21+ PUBLIC_SOURCE = 'https://go-api.ifrc.org/api/publicsiteappeals?Hidden=false&AppealsTypeID='
22+ FEDNET_SOURCE = 'https://go-api.ifrc.org/Api/FedNetAppeals?Hidden=false&AppealsTypeId='
23+
2124# WORK IN PROGRESS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2225
2326class Command (BaseCommand ):
@@ -38,15 +41,17 @@ def create_bilaterals_dict(self, records):
3841 bilaterals [rec ['APP_Code' ]] = rec ['AmountCHF' ]
3942 return bilaterals
4043
41- def load (self , url : str , file_field : str , field_inserted_date_field : str ):
44+ def load (self , url : str , is_fednet ):
4245 auth = (settings .APPEALS_USER , settings .APPEALS_PASS )
43- results = requests .get (url , auth = auth , headers = {'Accept' : 'application/json' }).json ()
44- for result in results :
45- try :
46- pass
47- # self.load_for_country(result, file_field, field_inserted_date_field)
48- except Exception :
49- logger .error ('Could not update AppealDocuments' , exc_info = True )
46+ for adtype in APPEAL_DOCUMENT_TYPES .filter (public_site_or_fednet = is_fednet ):
47+ results = requests .get (url + str (adtype .id ), auth = auth , headers = {'Accept' : 'application/json' }).json ()
48+ # import pdb; pdb.set_trace()
49+ for result in results :
50+ try :
51+ pass
52+ # self.load_for_country(result, file_field, field_inserted_date_field)
53+ except Exception :
54+ logger .error ('Could not update AppealDocuments' , exc_info = True )
5055
5156 def get_public_or_fednet_appealdocs (self ):
5257 PUBLIC_SOURCE = 'https://go-api.ifrc.org/api/publicsiteappeals?AppealsTypeID=1851&Hidden=false'
@@ -301,22 +306,29 @@ def parse_appeal_record(self, r, **options):
301306
302307 return fields
303308
304- def handle (self , * args , ** options ):
305- logger .info ('Starting appeals ingest' )
306- start_appeals_count = Appeal .objects .all ().count ()
307- try :
308- getFromAPI = self .get_public_or_fednet_appealdocs ()
309- except Exception as ex :
310- logger .error (f'Getting Appealdocs failed: { str (ex )} ' )
311- return
312- try :
313- new , modified , bilaterals = self .get_new_or_modified_appeals ()
314- except Exception as ex :
315- logger .error (f'Getting Appeals and AppealBilaterals failed: { str (ex )} ' )
316- return
317- logger .info (f'{ start_appeals_count } current appeals' )
318- logger .info (f'Creating { len (new )} new appeals' )
319- logger .info (f'Updating { len (modified )} existing appeals that MIGHT have been modified' )
309+ def handle (self , ** _ ):
310+ # Public
311+ self .stdout .write ('Fetching data for appealdocs:: PUBLIC' )
312+ self .load (PUBLIC_SOURCE , False )
313+ # Private
314+ self .stdout .write ('\n Fetching data for appealdocs:: FEDNET' )
315+ self .load (FEDNET_SOURCE , True )
316+
317+ # logger.info('Starting appeals ingest')
318+ # start_appeals_count = Appeal.objects.all().count()
319+ # try:
320+ # getFromAPI = self.get_public_or_fednet_appealdocs()
321+ # except Exception as ex:
322+ # logger.error(f'Getting Appealdocs failed: {str(ex)}')
323+ # return
324+ # try:
325+ # new, modified, bilaterals = self.get_new_or_modified_appeals()
326+ # except Exception as ex:
327+ # logger.error(f'Getting Appeals and AppealBilaterals failed: {str(ex)}')
328+ # return
329+ # logger.info(f'{start_appeals_count} current appeals')
330+ # logger.info(f'Creating {len(new)} new appeals')
331+ # logger.info(f'Updating {len(modified)} existing appeals that MIGHT have been modified')
320332#
321333# errors = []
322334# num_created = 0
0 commit comments