Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Update ACLED scraper
Browse files Browse the repository at this point in the history
Use email and key
  • Loading branch information
mcarans committed Oct 13, 2020
1 parent e435992 commit e6db043
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "3.6"
- "3.8"

#
# Command to install dependencies.
Expand Down
22 changes: 11 additions & 11 deletions acled.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def get_countries(countries_url, downloader):

def generate_dataset_and_showcase(base_url, downloader, folder, country):
countryname = country['countryname']
title = '%s - Conflict Data' % countryname
logger.info('Creating dataset: %s' % title)
slugified_name = slugify('ACLED Data for %s' % countryname).lower()
title = f'{countryname} - Conflict Data'
logger.info(f'Creating dataset: {title}')
slugified_name = slugify(f'ACLED Data for {countryname}').lower()
countryiso = country['iso3']
dataset = Dataset({
'name': slugified_name,
Expand All @@ -55,24 +55,24 @@ def generate_dataset_and_showcase(base_url, downloader, folder, country):
tags = ['hxl', 'violence and conflict', 'protests', 'security incidents']
dataset.add_tags(tags)

url = '%siso=%d' % (base_url, country['m49'])
filename = 'conflict_data_%s.csv' % countryiso
url = f'{base_url}iso={country["m49"]}'
filename = f'conflict_data_{countryiso}.csv'
resourcedata = {
'name': 'Conflict Data for %s' % countryname,
'name': f'Conflict Data for {countryname}',
'description': 'Conflict data with HXL tags'
}
quickcharts = {'cutdown': 2, 'cutdownhashtags': ['#date+year', '#adm1+name', '#affected+killed']}
success, results = dataset.download_and_generate_resource(downloader, url, hxltags, folder, filename, resourcedata,
yearcol='year', quickcharts=quickcharts)
if success is False:
logger.warning('%s has no data!' % countryname)
logger.warning(f'{countryname} has no data!')
return None, None

showcase = Showcase({
'name': '%s-showcase' % slugified_name,
'title': 'Dashboard for %s' % country['countryname'],
'notes': 'Conflict Data Dashboard for %s' % country['countryname'],
'url': 'https://www.acleddata.com/dashboard/#%03d' % country['m49'],
'name': f'{slugified_name}-showcase',
'title': f'Dashboard for {country["countryname"]}',
'notes': f'Conflict Data Dashboard for {country["countryname"]}',
'url': f'https://www.acleddata.com/dashboard/#{country["m49"]:03d}',
'image_url': 'https://www.acleddata.com/wp-content/uploads/2018/01/dash.png'
})
showcase.add_tags(tags)
Expand Down
2 changes: 1 addition & 1 deletion config/project_configuration.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Collector specific configuration
base_url: "https://api.acleddata.com/acled/read.csv?limit=0&terms=accept&"
base_url: "https://api.acleddata.com/acled/read.csv?limit=0&"
countries_url: "https://www.acleddata.com/download/3987/"
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
python-slugify==4.0.0
hdx-python-api==4.4.5
python-slugify==4.0.1
hdx-python-api==4.6.5
-r docker-requirements.txt
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():
configuration = Configuration.read()
base_url = configuration['base_url']
countries_url = configuration['countries_url']
with Download() as downloader:
with Download(extra_params_yaml=join(expanduser('~'), '.extraparams.yml'), extra_params_lookup=lookup) as downloader:
countries = get_countries(countries_url, downloader)
logger.info('Number of datasets to upload: %d' % len(countries))
for info, country in progress_storing_tempdir('ACLED', sorted(countries, key=lambda x: x['iso3']), 'iso3'):
Expand Down

0 comments on commit e6db043

Please sign in to comment.