1
0

Favro sync initial prototype

This commit is contained in:
Jon Michael Aanes 2024-09-26 16:03:06 +02:00
commit e1952c3f66

75
test.py Normal file
View File

@ -0,0 +1,75 @@
import requests
import secret_loader
from typing import Any
import functools
import dataclasses
URL_API_ROOT = 'https://favro.com/api/v1'
URL_GET_ALL_CARDS = URL_API_ROOT+'/cards'
URL_UPDATE_CARD = URL_API_ROOT+'/cards/{card_id}'
# Types
@dataclasses.dataclass(frozen=True)
class SeqId:
raw_id: int
@dataclasses.dataclass(frozen=True)
class CardId:
raw_id: str
# Authentication
secrets = secret_loader.SecretLoader()
FAVRO_ORG_ID = secrets.load_or_fail('FAVRO_ORGANIZATION_ID')
FAVRO_USERNAME = secrets.load_or_fail('FAVRO_USERNAME')
FAVRO_PASSWORD = secrets.load_or_fail('FAVRO_PASSWORD')
headers = {
'organizationId': FAVRO_ORG_ID,
'content-type': 'application/json',
}
SESSION = requests.Session()
def get_card_json(seqid: SeqId) -> dict[str, Any]:
params = {'cardSequentialId': seqid.raw_id}
response = SESSION.get(URL_GET_ALL_CARDS, headers=headers, auth=(FAVRO_USERNAME, FAVRO_PASSWORD), params = params)
response.raise_for_status()
json = response.json()
assert json['pages'] == 1
assert len(json['entities']) == 1
return json['entities'][0]
@functools.cache
def get_card_id(seqid: SeqId) -> CardId:
json = get_card_json(seqid)
return CardId(json['cardId'])
description = '''
I cannot remember what this card involved
# Tasks
- [ ] Why doesn't task work?
- [ ] Task 2
# Quotes
I love this card.
'''
def main(card_id: CardId):
json_body = {
'detailedDescription': description,
'descriptionFormat': 'markdown',
}
response = SESSION.put(URL_UPDATE_CARD.format(card_id=card_id.raw_id),
json=json_body, headers=headers, auth=(FAVRO_USERNAME, FAVRO_PASSWORD))
response.raise_for_status()
if __name__ == '__main__':
main(get_card_id(SeqId(4714)))