From b175bdbcc781b0b5297bd18becfb2217ecbce6bc Mon Sep 17 00:00:00 2001 From: hppeng Date: Sat, 25 Jun 2022 05:44:24 -0700 Subject: [PATCH] Example argparse --- py_script/get.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/py_script/get.py b/py_script/get.py index 9daa4fc..9cf48a0 100644 --- a/py_script/get.py +++ b/py_script/get.py @@ -7,13 +7,18 @@ Usage: python get.py [url or command] [outfile rel path] Relevant page: https://docs.wynncraft.com/ """ -import requests +import argparse import json -import numpy as np -import sys -#req can either be a link to an API page OR a preset default -req, outfile = sys.argv[1], sys.argv[2] +import numpy as np +import requests + +parser = argparse.ArgumentParser(description="Pull data from wynn API.") +parser.add_argument('target', help='an API page, or preset [items, ings, recipes, terrs, maploc]') +parser.add_argument('outfile', help='output file to dump results into') +args = parser.parse_args() + +req, outfile = args.target, args.outfile CURR_WYNN_VERS = 2.0 @@ -57,4 +62,4 @@ else: response['version'] = CURR_WYNN_VERS -json.dump(response, open(outfile, "w+")) \ No newline at end of file +json.dump(response, open(outfile, "w+"))