Skip to content

Commit 78204b7

Browse files
Merge pull request #54 from AlexanderWillner/main
method for getting API token
2 parents 3918076 + 40fb244 commit 78204b7

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,8 @@ upload: build ## Upload the code
104104
@echo "########################"
105105
@$(PYTHON) -m twine upload dist/things.py* -u __token__ -p "${PYPI_API_TOKEN}"
106106

107+
get-db:
108+
@cp tests/main.sqlite* ~/Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/
109+
107110
copy-db:
108111
@cp ~/Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/main.sqlite* tests/

tests/main.sqlite

0 Bytes
Binary file not shown.

tests/main.sqlite-shm

0 Bytes
Binary file not shown.

tests/main.sqlite-wal

8.08 KB
Binary file not shown.

tests/test_things.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
class ThingsCase(unittest.TestCase):
1515
"""Class documentation goes here."""
1616

17+
def test_get_api_token(self):
18+
"""Test get API token."""
19+
expected = "vKkylosuSuGwxrz7qcklOw"
20+
token = things.token(**FILEPATH)
21+
self.assertEqual(token, expected)
22+
1723
def test_search(self):
1824
"""Test search."""
1925
tasks = things.search("wrong_query", **FILEPATH)

things/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
tasks,
2020
today,
2121
todos,
22+
token,
2223
upcoming,
2324
)
2425
from things.database import Database # noqa

things/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,17 @@ def deadlines(**kwargs):
530530

531531
# Interact with Things app
532532

533+
def token(**kwargs) -> str:
534+
"""
535+
Returns the API token.
536+
537+
See <a href="https://culturedcode.com/things/support/articles/2803573/">
538+
Things URL Scheme</a> for details.
539+
"""
540+
database = pop_database(kwargs)
541+
542+
return database.get_api_token()
543+
533544

534545
def link(uuid):
535546
"""

things/database.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Database:
8080
TABLE_AREATAG = "TMAreaTag"
8181
TABLE_CHECKLIST_ITEM = "TMChecklistItem"
8282
TABLE_META = "Meta"
83+
TABLE_SETTINGS = "TMSettings"
8384
DATE_CREATE = "creationDate"
8485
DATE_MOD = "userModificationDate"
8586
DATE_DEADLINE = "dueDate"
@@ -415,6 +416,21 @@ def get_version(self):
415416
plist_bytes = result[0].encode()
416417
return plistlib.loads(plist_bytes)
417418

419+
def get_api_token(self):
420+
"""Get Things API token."""
421+
422+
sql_query = f"""
423+
SELECT
424+
uriSchemeAuthenticationToken
425+
FROM
426+
{self.TABLE_SETTINGS}
427+
WHERE
428+
uuid = 'RhAzEf6qDxCD5PmnZVtBZR'
429+
"""
430+
result = self.execute_query(sql_query, row_factory=list_factory)
431+
432+
return result[0]
433+
418434
def get_count(self, sql):
419435
"""Count number of results."""
420436
sql_query = f"""SELECT COUNT(uuid) FROM ({sql})"""

0 commit comments

Comments
 (0)