Commit 87a58eed authored by Conor Anderson's avatar Conor Anderson

Improve inventory download behaviour and add setup.py

parent ffb4193b
Pipeline #45915953 passed with stages
in 4 minutes and 30 seconds
......@@ -82,22 +82,28 @@ def guess_skip(filename):
@lru_cache()
def get_inventory(force=False):
def get_inventory(behaviour):
filename = "Station Inventory EN.csv"
if not os.path.isfile(filename):
if force:
print("Downloading", filename, "to the current working directory")
download_file("ftp://[email protected]/Pub/Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv",
filename)
else:
warn("Cannot find the station inventory in the current working directory",
"The data will be cached for this session. If running from the command-line,",
"consider downloading the data with: \"ec3 inv\".")
filename = os.path.join(tempdir(), filename)
print("Downloading", os.path.basename(filename), "to", os.path.dirname(filename))
download_file("ftp://[email protected]/Pub/Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv",
filename)
if behaviour == "update":
print("Downloading", filename, "to the current working directory")
download_file("ftp://[email protected]/Pub/Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv",
filename)
else:
if not os.path.isfile(filename):
if behaviour == "local":
exit("Cannot find the station inventory in the current working directory",
"Downloading the data with: \"ec3 inv\".")
elif behaviour == "session":
warn("Cannot find the station inventory in the current working directory",
"The data will be cached for this session. If running from the command-line,",
"consider downloading the data with: \"ec3 inv\".")
filename = os.path.join(tempdir(), filename)
print("Downloading", os.path.basename(filename), "to", os.path.dirname(filename))
download_file("ftp://[email protected]/Pub/Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv",
filename)
else:
raise Exception("Unknown behaviour passed.")
inv = pd.read_csv(filename, skiprows = guess_skip(filename))
# Correct some placeholder coordinates (list comp because otherwise I get warnings)
......@@ -130,7 +136,7 @@ def find_station(name=None, province=None, period=None, type=None, detect_recode
Desired distance from target (in km); Defaul: range(101).
"""
inv = get_inventory()
inv = get_inventory(behaviour="session")
filt = inv.copy()
if name is not None:
......@@ -330,6 +336,9 @@ if __name__ == '__main__':
print(arguments)
if arguments['find']:
null = get_inventory(behaviour="local")
if arguments['--period'] is not None:
if not bool(re.search(r'(^[0-9]{4}$|^[0-9]{4}:[0-9]{4}$)', arguments['--period'])):
warn("Invalid period format.")
......@@ -382,7 +391,7 @@ if __name__ == '__main__':
exit(0)
if arguments['inv']:
null=get_inventory(force=True)
null = get_inventory(behaviour="update")
exit(0)
if arguments['get']:
......
from __future__ import with_statement
from setuptools import setup
import ec3
ec3_classifiers = [
"Programming Language :: Python :: 3",
]
with open("README.md", "r") as file:
ec3_long_description = file.read()
setup(name="ec3",
version=ec3.__version__,
author="Conor Anderson",
author_email="[email protected]",
url="https://gitlab.com/ConorIA/ec3.py",
py_modules=["ec3"],
description="Access climate data from Government of Canada's Historical Climate Data API",
long_description=ec3_long_description,
license="GPL3",
classifiers=ec3_classifiers,
python_requires=">=3.6",
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment