-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,292 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"retrieveType": "script", | ||
"download": { | ||
"path": "./processing.py", | ||
"function": "collect", | ||
"args": [ | ||
"{OUTPATH}" | ||
], | ||
"output": "lists.csv" | ||
}, | ||
"conversion": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from pathlib import Path | ||
import pandas as pd | ||
import requests | ||
|
||
def collect(outputPath: Path) -> None: | ||
baseURL = "https://lists-ws.test.ala.org.au/" | ||
session = requests.Session() | ||
recordsPerPage = 100 | ||
|
||
def getURL(endpoint: str, params: dict, pageSize: int, page: int = 1) -> dict: | ||
fields = dict(params) | ||
fields["page"] = page | ||
fields["pageSize"] = pageSize | ||
|
||
url = f"{baseURL}{endpoint}?" + "&".join(f"{k}={v}" for k, v in fields.items()) | ||
response = session.get(url) | ||
data = response.json() | ||
return data | ||
|
||
listsMetadata = outputPath.parent / "metadata.csv" | ||
if not listsMetadata.exists(): | ||
records = [] | ||
metadataEndpoint = "speciesList/" | ||
|
||
query = {"tag": "arga"} | ||
data = getURL(metadataEndpoint, query, recordsPerPage) | ||
records.extend(data["lists"]) | ||
totalItems = data["listCount"] | ||
remainingCalls = ((totalItems / recordsPerPage).__ceil__()) - 1 | ||
|
||
for call, _ in enumerate(range(remainingCalls), start=2): | ||
data = getURL(metadataEndpoint, query, recordsPerPage, call) | ||
records.extend(data["lists"]) | ||
|
||
df = pd.DataFrame.from_records(records) | ||
df = df.drop(["description"], axis=1) | ||
df.to_csv(listsMetadata, index=False) | ||
else: | ||
df = pd.read_csv(listsMetadata) | ||
|
||
records = [] | ||
for id in df["id"]: | ||
page = 1 | ||
while True: | ||
print(f"Getting page #{page} for id {id}", end="\r") | ||
data = getURL(f"speciesListItems/{id}", {}, recordsPerPage, page) | ||
if not data: | ||
break | ||
|
||
records.extend(data) | ||
page += 1 | ||
|
||
print() | ||
|
||
df2 = pd.DataFrame.from_records(records) | ||
df = df.rename(columns={"id": "speciesListID", "version": "speciesListVersion"}) | ||
df = df.merge(df2, "outer", on="speciesListID") | ||
df2.to_csv(outputPath, index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,11 @@ | |
"function": "dwcAugment" | ||
} | ||
] | ||
}, | ||
"update": { | ||
"type": "weekly", | ||
"day": "sunday", | ||
"time": 9, | ||
"repeat": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"retrieveType": "url", | ||
"datasetID": "ARGA:TL:0001018", | ||
"download": { | ||
"files": [ | ||
{ | ||
"url": "https://api.checklistbank.org/dataset/304708/export.zip?extended=true&format=DwCA", | ||
"name": "catalogueOfLife.zip" | ||
} | ||
] | ||
}, | ||
"processing": { | ||
"final": [ | ||
{ | ||
"path": ".../tools/zipping.py", | ||
"function": "extract", | ||
"args": [ | ||
"{INPATH}", | ||
"{OUTDIR}" | ||
], | ||
"output": "{INSTEM}" | ||
}, | ||
{ | ||
"path": "./processing.py", | ||
"function": "process", | ||
"args": [ | ||
"{INPATH}", | ||
"{OUTPATH}" | ||
], | ||
"output": "col.csv" | ||
} | ||
] | ||
}, | ||
"conversion": {}, | ||
"update": { | ||
"type": "weekly", | ||
"day": "sunday", | ||
"time": 9, | ||
"repeat": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
def process(folderPath: Path, outputPath: Path) -> None: | ||
|
||
def readCSV(fileName: str) -> pd.DataFrame: | ||
return pd.read_csv(folderPath / fileName, sep="\t", on_bad_lines="skip", low_memory=False) | ||
|
||
df = readCSV("Taxon.tsv") | ||
|
||
speciesProfile = readCSV("SpeciesProfile.tsv") | ||
df = df.merge(speciesProfile, "left", "dwc:taxonID") | ||
|
||
vernacularNames = readCSV("VernacularName.tsv") | ||
records = {} | ||
for _, row in vernacularNames.iterrows(): | ||
taxID = row["dwc:taxonID"] | ||
if taxID not in records: | ||
records[taxID] = {} | ||
|
||
language = row["dcterms:language"] | ||
if language not in records[taxID]: | ||
records[taxID][language] = [] | ||
|
||
records[taxID][language].append(row["dwc:vernacularName"]) | ||
|
||
vernacular = pd.DataFrame.from_dict(records, orient="index") | ||
df = df.merge(vernacular, "left", left_on="dwc:taxonID", right_on=vernacular.index) | ||
df.to_csv(outputPath, index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,11 @@ | |
} | ||
} | ||
] | ||
}, | ||
"update": { | ||
"type": "weekly", | ||
"day": "sunday", | ||
"time": 9, | ||
"repeat": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,11 @@ | |
"output": "cleanedgoat.csv" | ||
} | ||
] | ||
}, | ||
"update": { | ||
"type": "weekly", | ||
"day": "sunday", | ||
"time": 9, | ||
"repeat": 2 | ||
} | ||
} |
Oops, something went wrong.