Skip to content

Commit

Permalink
Merge pull request #25 from acdh-oeaw/24-method-to-get-user-id-by-use…
Browse files Browse the repository at this point in the history
…r-name

method to fetch user ID by username added
  • Loading branch information
csae8092 authored Aug 17, 2023
2 parents 6b34f59 + 9f7ff8e commit 41151dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ def test_010_create_report(self):
filter_string="acdh-transkribus-utils", transcription_threshold=1
)
self.assertEqual(len(status), 5)

def test_011_user_id(self):
client = CLIENT
user_id = client.get_user_id(client.user)
self.assertTrue(user_id)
22 changes: 21 additions & 1 deletion transkribus_utils/transkribus_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,24 @@ def upload_iiif_from_url(self, iiif_url, col_id):
)
return False

def create_status_report(self, filter_string: str, transcription_threshold: int = 10) -> list:
def get_user_id(self, user_name: str) -> int:
"""returns the ID of the passed in user name
:param user_name: the user name
:return: the user's ID
"""
r = requests.get(
f"{self.base_url}/user/list",
cookies=self.login_cookie,
params={"user": user_name},
)
response = r.json()
user_id = response["trpUser"][0]["userId"]
return user_id

def create_status_report(
self, filter_string: str, transcription_threshold: int = 10
) -> list:
"""generates a report about the documents in the filterd collections
:param filter_string: a string the collection name should contain
:param transcription_threshold: minimum number of transcribed lines
Expand Down Expand Up @@ -472,10 +489,13 @@ def __init__(
) -> None:
if user is None:
user = os.environ.get("TRANSKRIBUS_USER", None)
self.user = user
if user is None:
raise AttributeError(
"Transkribus username needs to be set in environments or in init"
)
else:
self.user = user
if password is None:
password = os.environ.get("TRANSKRIBUS_PASSWORD", None)
if password is None:
Expand Down

0 comments on commit 41151dd

Please sign in to comment.