From 6d721910d2adec51d5b6c7fbc93340ec26fb5eb7 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Sat, 10 Apr 2021 15:21:38 +0100 Subject: [PATCH] add every country in the world, apart from those which don't have capitals --- .gitignore | 2 ++ Makefile | 7 ++++++ scripts/generate_countries_list.py | 38 ++++++++++++++++++++++++++++++ src/game.js | 8 ------- src/index.html | 3 ++- 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100755 scripts/generate_countries_list.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..890c883 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +src/countries.json +*/*.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b32738 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: src/countries.json + +src/countries.json: + python scripts/generate_countries_list.py countries/countries.json > src/countries.json + +clean: + rm -rf src/countries.json diff --git a/scripts/generate_countries_list.py b/scripts/generate_countries_list.py new file mode 100755 index 0000000..d2eb28c --- /dev/null +++ b/scripts/generate_countries_list.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import sys +import json + + +def get_args(): + """ Get command line arguments """ + + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('file', help="The countries.json file to generate the output from", type=str) + return parser.parse_args() + + +def main(args): + """ Entry point for script """ + with open(args.file) as fp: + countries = json.load(fp) + + r = {} + + for country in countries: + if len(country['capital']) < 1 or country['capital'][0] is None: + continue + r[country['name']['common']] = country['capital'][0] + + print('capitals = ', end='') + print(json.dumps(r)) + + return 0 + + +if __name__ == '__main__': + try: + sys.exit(main(get_args())) + except KeyboardInterrupt: + sys.exit(0) diff --git a/src/game.js b/src/game.js index d077b28..e68a272 100644 --- a/src/game.js +++ b/src/game.js @@ -1,13 +1,5 @@ "use strict"; -var capitals = { - "England": "London", - "France": "Paris", - "the USA": "Washington D.C.", - "India": "New Dehli", - "Bangladesh": "Dhaka" -} - var question_list = null; const capitals_list = Object.values(capitals); const date = new Date(); diff --git a/src/index.html b/src/index.html index 380c953..96e0824 100644 --- a/src/index.html +++ b/src/index.html @@ -34,5 +34,6 @@ - + +