Skip to content

Commit

Permalink
Allow passing the URL or file args from script
Browse files Browse the repository at this point in the history
* Add 'url' and 'file' options to the configuration file
* Add '--url' and '--file' flags to archmap.py
* Update docs
  • Loading branch information
guyfawcus committed Oct 27, 2017
1 parent 825deeb commit a4f2e33
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions archmap.conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 20 additions & 1 deletion archmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand All @@ -246,13 +255,17 @@ 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']
output_file_csv = config['files']['csv']
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
Expand All @@ -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

Expand All @@ -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':
Expand Down
8 changes: 8 additions & 0 deletions docs/usage/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down

0 comments on commit a4f2e33

Please sign in to comment.