Skip to content

Commit

Permalink
fix url error
Browse files Browse the repository at this point in the history
  • Loading branch information
Simran committed Apr 15, 2021
1 parent 76445e1 commit 4b1d708
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions mapactionpy_controller/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import urllib
import urllib.error
import os
import pycountry
from mapactionpy_controller import _get_validator_for_config_schema
Expand Down Expand Up @@ -33,25 +34,30 @@ def __init__(self, event_file):
self.default_source_organisation_url = event_def['default_source_organisation_url']
self.default_publishing_base_url = event_def['default_publishing_base_url']
op_id = (event_def['operation_id']).lower()
self.operation_id = self._is_valid_group_id(op_id, self.default_publishing_base_url)
self.operation_id = _is_valid_group_id(op_id, self.default_publishing_base_url)
self.deployment_primary_email = event_def['deployment_primary_email']
self.default_disclaimer_text = event_def['default_disclaimer_text']
self.default_donor_credits = event_def['default_donor_credits']
# self.donors = event_def['donors']
self.country_name = _parse_country_name(event_def)

def _is_valid_group_id(self, operation_id, default_publishing_base_url):
# Check if valid group number then return
url = default_publishing_base_url + '/api/3/action/group_show?id={}'.format(operation_id)
try:
response = urllib.request.urlopen(url)
response_dict = json.loads(response.read())
if not response_dict['success']:
raise ValueError('Not a valid Group ID on the target CKAN Site')
except Exception:
raise ValueError('Not a valid Group ID on the target CKAN Site')

return operation_id

def _is_valid_group_id(operation_id, default_publishing_base_url):
# Check if valid group number then return
print(default_publishing_base_url)
print(operation_id)
url = default_publishing_base_url + '/api/3/action/group_show?id={}'.format(operation_id)
try:
response_get = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
print(e.code)
raise ValueError('Not a valid URL, error = {}'.format(e.code))
response_dict = json.loads(response_get.read())
if response_dict['result']['name'] == operation_id:
pass
else:
raise ValueError('Not a valid Group ID on the target CKAN Site')
return operation_id


def _parse_country_name(event_def):
Expand Down

0 comments on commit 4b1d708

Please sign in to comment.