Browse Source

try catch statement

main
Cailean Finn 6 months ago
parent
commit
cb66421638
  1. 5
      app.py

5
app.py

@ -74,13 +74,14 @@ class WikiApp(Flask):
for category in categories: for category in categories:
response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:'+category+']] [[Opportunities:Deadline::<=' + future_date.strftime("%Y-%m-%d") + ']] [[Opportunities:Deadline::>='+ pub_date.strftime("%Y-%m-%d") + ']] |?Opportunities:Deadline|?Opportunities:Name|?Opportunities:Location|?Opportunities:Organiser/s|?Opportunities:Type|?Opportunities:Source', 'format': 'json', 'formatversion': '2'}) response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:'+category+']] [[Opportunities:Deadline::<=' + future_date.strftime("%Y-%m-%d") + ']] [[Opportunities:Deadline::>='+ pub_date.strftime("%Y-%m-%d") + ']] |?Opportunities:Deadline|?Opportunities:Name|?Opportunities:Location|?Opportunities:Organiser/s|?Opportunities:Type|?Opportunities:Source', 'format': 'json', 'formatversion': '2'})
data = response.json() data = response.json()
opp_info = {} opp_info = {}
if not data['query']['results']: if not data['query']['results']:
return {} return {}
else: else:
for page_title, page_data in data['query']['results'].items(): for page_title, page_data in data['query']['results'].items():
if 'printouts' in page_data and 'Opportunities:Deadline' in page_data['printouts']: if 'printouts' in page_data and 'Opportunities:Deadline' in page_data['printouts']:
try:
print(page_title)
type = page_data['printouts']['Opportunities:Type'][0] type = page_data['printouts']['Opportunities:Type'][0]
name = page_data['printouts']['Opportunities:Name'][0] name = page_data['printouts']['Opportunities:Name'][0]
deadline = page_data['printouts']['Opportunities:Deadline'][0]['raw'] deadline = page_data['printouts']['Opportunities:Deadline'][0]['raw']
@ -97,6 +98,8 @@ class WikiApp(Flask):
opp_page_list[type] = [] opp_page_list[type] = []
opp_page_list[type].append(opp_info) opp_page_list[type].append(opp_info)
except:
print(f"issue with parsing, {page_title}")
return opp_page_list return opp_page_list

Loading…
Cancel
Save