diff --git a/README.rst b/README.rst index 527d153..a388ca8 100644 --- a/README.rst +++ b/README.rst @@ -42,14 +42,18 @@ The config file should be placed in ``/etc/archmap.conf``, this can be overridde Use --- -Running ``archmap --help`` will display this help message:: +Running ``archmap --help`` will display this help message: - archmap [-h] [-v] [--config FILE] [--users FILE] [--geojson FILE] [--kml FILE] [--csv FILE] +.. code-block:: none + + archmap [-h] [-v] [--config FILE] [--url URL] [--file FILE] [--users FILE] [--geojson FILE] [--kml FILE] [--csv FILE] optional arguments: -h, --help show this help message and exit -v, --verbose Show info messages --config FILE Use an alternative configuration file instead of /etc/archmap.conf + --url URL Use an alternative URL to parse the wiki list from + --file FILE Use a file to parse the wiki list from --users FILE Output the list of users to FILE, use 'no' to disable output --geojson FILE Output the GeoJSON to FILE, use 'no' to disable output --kml FILE Output the KML to FILE, use 'no' to disable output diff --git a/archmap.conf b/archmap.conf index 9dcde9d..d8ffc23 100644 --- a/archmap.conf +++ b/archmap.conf @@ -1,4 +1,9 @@ [files] +# Define where to get the wiki list from. +# If a file path is supplied to 'default_file', it will be used instead of the URL +url = https://wiki.archlinux.org/index.php/ArchMap/List +file = + # The location to save the list of users and the GIS files, # use 'no' to disable output. users = /tmp/archmap_users.txt diff --git a/archmap.py b/archmap.py index 8ac24dc..d06dac3 100755 --- a/archmap.py +++ b/archmap.py @@ -29,6 +29,11 @@ # they will override the settings in the config file. default_config = '/etc/archmap.conf' +# Define where to get the wiki list from. +# If a file path is supplied to 'default_file', it will be used instead of the URL +default_url = 'https://wiki.archlinux.org/index.php/ArchMap/List' +default_file = '' + # Set the output locations for users, GeoJSON, KML and CSV. # Setting any of the following to 'no' will disable the output. # These settings are overridden by the config file, if it exists. @@ -231,6 +236,10 @@ def make_csv(parsed_users, output_file): parser.add_argument('--config', metavar='FILE', default=default_config, help='Use an alternative configuration file \ instead of /etc/archmap.conf') + parser.add_argument('--url', metavar='URL', + help='Use an alternative URL to parse the wiki list from') + parser.add_argument('--file', metavar='FILE', + help='Use a file to parse the wiki list from') parser.add_argument('--users', metavar='FILE', help="Output the user list to FILE, use 'no' to disable output") parser.add_argument('--geojson', metavar='FILE', @@ -246,6 +255,8 @@ def make_csv(parsed_users, output_file): config = ConfigParser() config.read(args.config) verbosity = int(config['extras']['verbosity']) + input_url = config['files']['url'] + input_file = config['files']['file'] output_file_users = config['files']['users'] output_file_geojson = config['files']['geojson'] output_file_kml = config['files']['kml'] @@ -253,6 +264,8 @@ def make_csv(parsed_users, output_file): except Exception as e: log.warning('Warning: Configuation file error: {}. Using defaults'.format(e)) verbosity = default_verbosity + input_url = default_url + input_file = default_file output_file_users = default_users output_file_geojson = default_geojson output_file_kml = default_kml @@ -266,6 +279,12 @@ def make_csv(parsed_users, output_file): if verbosity >= 1: log.setLevel(logging.INFO) + if args.url is not None: + input_url = args.url + + if args.file is not None: + input_file = args.file + if args.users is not None: output_file_users = args.users @@ -285,7 +304,7 @@ def make_csv(parsed_users, output_file): output_file_csv == 'no': log.warning('There is nothing to do') else: - users = get_users() + users = get_users(url=input_url, local=input_file) parsed_users = parse_users(users) if output_file_users != 'no': diff --git a/docs/usage/basic_usage.rst b/docs/usage/basic_usage.rst index 0fbea43..888e118 100644 --- a/docs/usage/basic_usage.rst +++ b/docs/usage/basic_usage.rst @@ -32,6 +32,14 @@ You can specify the output location for the user list text, GeoJSON, KML and CSV archmap --users /tmp/archmap_users.txt --geojson /tmp/archmap.geojson --kml /tmp/archmap.kml --csv /tmp/archmap.csv +If you would like to parse an alternate copy of the wiki list, simply pass either the --url or --file flags:: + + archmap --url https://wiki.archlinux.org/index.php?title=ArchMap/List&oldid=131196 + +or :: + + archmap --file "$HOME/Downloads/ArchMap_List - ArchWiki.html" + Logging ------- If the script is run on a system that uses systemd, it will log to it using the syslog identifier - "archmap".