Commit 9eb4fd32 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Rewrite of prepare, list_recipes, list_local_databases, remove and card...

Rewrite of prepare, list_recipes, list_local_databases, remove and card download script\nOther commands will follow
parent 1996f4bd
import wget
import tarfile
import json
import datetime
import logging
def download(url):
logging.info("Downloading " + url)
filename = wget.download(url)
print("") # wget does not add a newline to its download bar
return filename
def extract(filename):
logging.info("Extracting " + filename)
with tarfile.open(filename, 'r') as tar:
tar.extractall()
def create_metadata(name,
tool,
description=None,
creation_date=datetime.datetime.now().isoformat(),
version=datetime.date.today().isoformat(),
):
metadata = {
'name': name,
'tool': tool,
'description': description,
'creation_date': creation_date,
'version': version
}
with open("metadata.json", "w") as metadata_file:
logging.info("Writing metadata " + json.dumps(metadata))
json.dump(metadata, metadata_file)
This diff is collapsed.
#!/usr/bin/env python3
import dbman.helper as h
import json
import logging
logging.basicConfig(level=logging.INFO)
dbname = "card"
dbdescription = "The Comprehensive Antibiotic Resistance Database"
url = "https://card.mcmaster.ca/latest/data"
# the card version is either available on the homepage or inside the card.json file
# here we use the card.json file
def lookup_card_version():
with open("card.json") as card:
data = json.load(card)
version = data["_version"]
return version
# download archive
fn = h.download(url)
# extract archive
h.extract(fn)
# detect version
version = lookup_card_version()
# write metadata file
h.create_metadata(dbname, "download", dbdescription, version=version)
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