File tree Expand file tree Collapse file tree 8 files changed +37
-0
lines changed Expand file tree Collapse file tree 8 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -104,5 +104,8 @@ upload: build ## Upload the code
104
104
@echo " ########################"
105
105
@$(PYTHON ) -m twine upload dist/things.py* -u __token__ -p " ${PYPI_API_TOKEN} "
106
106
107
+ get-db :
108
+ @cp tests/main.sqlite* ~ /Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/
109
+
107
110
copy-db :
108
111
@cp ~ /Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/main.sqlite* tests/
Original file line number Diff line number Diff line change 14
14
class ThingsCase (unittest .TestCase ):
15
15
"""Class documentation goes here."""
16
16
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
+
17
23
def test_search (self ):
18
24
"""Test search."""
19
25
tasks = things .search ("wrong_query" , ** FILEPATH )
Original file line number Diff line number Diff line change 19
19
tasks ,
20
20
today ,
21
21
todos ,
22
+ token ,
22
23
upcoming ,
23
24
)
24
25
from things .database import Database # noqa
Original file line number Diff line number Diff line change @@ -530,6 +530,17 @@ def deadlines(**kwargs):
530
530
531
531
# Interact with Things app
532
532
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
+
533
544
534
545
def link (uuid ):
535
546
"""
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ class Database:
80
80
TABLE_AREATAG = "TMAreaTag"
81
81
TABLE_CHECKLIST_ITEM = "TMChecklistItem"
82
82
TABLE_META = "Meta"
83
+ TABLE_SETTINGS = "TMSettings"
83
84
DATE_CREATE = "creationDate"
84
85
DATE_MOD = "userModificationDate"
85
86
DATE_DEADLINE = "dueDate"
@@ -415,6 +416,21 @@ def get_version(self):
415
416
plist_bytes = result [0 ].encode ()
416
417
return plistlib .loads (plist_bytes )
417
418
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
+
418
434
def get_count (self , sql ):
419
435
"""Count number of results."""
420
436
sql_query = f"""SELECT COUNT(uuid) FROM ({ sql } )"""
You can’t perform that action at this time.
0 commit comments