[Chore] Linted Files (#150)

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#150
This commit is contained in:
2025-10-09 07:25:13 +13:00
parent 22f0bbe10b
commit afeb56622c
50 changed files with 5616 additions and 4408 deletions

View File

@ -1,57 +1,58 @@
from csv import DictReader
from django.core.management.base import BaseCommand
from django.db import transaction
from epdb.models import *
from epdb.models import Compound, CompoundStructure, Reaction, ExternalDatabase, ExternalIdentifier
class Command(BaseCommand):
STR_TO_MODEL = {
'Compound': Compound,
'CompoundStructure': CompoundStructure,
'Reaction': Reaction,
"Compound": Compound,
"CompoundStructure": CompoundStructure,
"Reaction": Reaction,
}
STR_TO_DATABASE = {
'ChEBI': ExternalDatabase.objects.get(name='ChEBI'),
'RHEA': ExternalDatabase.objects.get(name='RHEA'),
'KEGG Reaction': ExternalDatabase.objects.get(name='KEGG Reaction'),
'PubChem Compound': ExternalDatabase.objects.get(name='PubChem Compound'),
'PubChem Substance': ExternalDatabase.objects.get(name='PubChem Substance'),
"ChEBI": ExternalDatabase.objects.get(name="ChEBI"),
"RHEA": ExternalDatabase.objects.get(name="RHEA"),
"KEGG Reaction": ExternalDatabase.objects.get(name="KEGG Reaction"),
"PubChem Compound": ExternalDatabase.objects.get(name="PubChem Compound"),
"PubChem Substance": ExternalDatabase.objects.get(name="PubChem Substance"),
}
def add_arguments(self, parser):
parser.add_argument(
'--data',
"--data",
type=str,
help='Path of the ID Mapping file.',
help="Path of the ID Mapping file.",
required=True,
)
parser.add_argument(
'--replace-host',
"--replace-host",
type=str,
help='Replace https://envipath.org/ with this host, e.g. http://localhost:8000/',
help="Replace https://envipath.org/ with this host, e.g. http://localhost:8000/",
)
@transaction.atomic
def handle(self, *args, **options):
with open(options['data']) as fh:
with open(options["data"]) as fh:
reader = DictReader(fh)
for row in reader:
clz = self.STR_TO_MODEL[row['model']]
clz = self.STR_TO_MODEL[row["model"]]
url = row['url']
if options['replace_host']:
url = url.replace('https://envipath.org/', options['replace_host'])
url = row["url"]
if options["replace_host"]:
url = url.replace("https://envipath.org/", options["replace_host"])
instance = clz.objects.get(url=url)
db = self.STR_TO_DATABASE[row['identifier_type']]
db = self.STR_TO_DATABASE[row["identifier_type"]]
ExternalIdentifier.objects.create(
content_object=instance,
database=db,
identifier_value=row['identifier_value'],
url=db.url_pattern.format(id=row['identifier_value']),
is_primary=False
identifier_value=row["identifier_value"],
url=db.url_pattern.format(id=row["identifier_value"]),
is_primary=False,
)