Skip to content

Commit 17396cd

Browse files
Merge pull request #238 from ARGA-Genomes/alaProfiles
Ala Profiles Update
2 parents 7b03c60 + 17e210f commit 17396cd

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

dataSources/ala/profiles/config.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
"subsections": {
44
"kamilaroi": {},
55
"noongar": {},
6-
"southeastarnhemland": {},
7-
"mangrovewatch": {},
6+
"southEastarnHemland": {},
7+
"mangroveWatch": {},
88
"weeds-australia": {}
99
},
1010
"downloading": {
1111
"path": "./processing.py",
1212
"function": "collect",
1313
"args": [
1414
"{OUT-DIR}",
15-
"<SUB>",
16-
"../token.json"
15+
"<SUB>"
1716
],
1817
"output": "<SUB>.csv"
1918
},
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
1-
import json
21
import requests
2+
import pandas as pd
33
from pathlib import Path
4+
from lib.secrets import secrets
5+
import lib.downloading as dl
6+
from lib.progressBar import ProgressBar
7+
import logging
48
import lib.dataframes as dff
5-
import pandas as pd
69

7-
def collect(outputDir: Path, profile: str, tokenFilePath: Path) -> None:
8-
with open(tokenFilePath) as fp:
9-
token = json.load(fp)
10+
def collect(outputDir: Path, profile: str) -> None:
11+
session = requests.session()
12+
13+
response = session.post(
14+
"https://auth.ala.org.au/cas/oidc/oidcAccessToken",
15+
headers={"Content-Type": "application/x-www-form-urlencoded"},
16+
data="grant_type=client_credentials&scope=openid email profile roles",
17+
auth=dl.buildAuth(secrets.ala.id, secrets.ala.secret)
18+
)
19+
20+
accessToken = response.json()["access_token"]
1021

11-
bearerToken = token["access_token"]
1222
baseURL = "https://api.ala.org.au/profiles"
1323
endpoint = f"/api/opus/{profile}/profile?pageSize=1000"
14-
response = requests.get(baseURL + endpoint, headers={"Authorization": f"Bearer {bearerToken}"})
24+
response = requests.get(baseURL + endpoint, headers={"Authorization": f"Bearer {accessToken}"})
1525
data = response.json()
1626

1727
if "message" in data and "not authorized" in data["message"]:
18-
print("Failed to authorize, please make sure bearer token is valid.")
28+
logging.error("Failed to authorize, please make sure bearer token is valid.")
1929
return
2030

21-
print(f"Accessing profile: {profile}")
31+
logging.info(f"Accessing profile: {profile}")
32+
33+
dataLength = len(data)
34+
logging.info(f"Found {dataLength} records")
2235

36+
progress = ProgressBar(dataLength)
2337
records = []
24-
for idx, entry in enumerate(data, start=1):
38+
for entry in data:
2539
uuid = entry["uuid"]
26-
print(f"At record: {idx}", end="\r")
27-
28-
response = requests.get(baseURL + f"/api/opus/{profile}/profile/{uuid}", headers={"Authorization": f"Bearer {bearerToken}"})
40+
response = requests.get(baseURL + f"/api/opus/{profile}/profile/{uuid}", headers={"Authorization": f"Bearer {accessToken}"})
2941
records.append(response.json())
30-
print()
42+
progress.update()
3143

3244
df = pd.DataFrame.from_records(records)
3345
df = dff.removeSpaces(df)
34-
df.to_csv(outputDir / f"{profile}.csv", index=False)
46+
df.to_csv(outputDir / f"{profile}.csv", index=False)

src/lib/data/sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _buildSourceName(self, locationName: str, databaseName: str, subsectionName:
2525
return f"{locationName}{self._divider}{databaseName}" + (f"{self._divider}{subsectionName}" if subsectionName else "")
2626

2727
def _splitSourceName(self, sourceName: str) -> tuple[str, str, str]:
28-
sourceSections = sourceName.split(self._divider)
28+
sourceSections = sourceName.split(self._divider, 2)
2929

3030
if len(sourceSections) <= 1:
3131
return sourceName, "", ""

0 commit comments

Comments
 (0)