todoist_interface/todoist_interface/todoist.py

31 lines
848 B
Python
Raw Normal View History

2021-11-06 19:06:34 +01:00
import requests
2021-11-06 20:07:57 +01:00
import json
2021-11-06 19:06:34 +01:00
class TodoistAPI:
url = "https://api.todoist.com/rest/v1/"
def __init__(self, token: str):
self.token = token
def get_get_tasks_by_filter(self, filter: str):
"""
Returns all tasks from todoist
"""
response = requests.get(
self.url + '/tasks',
headers={'Authorization': 'Bearer ' + self.token},
params={"filter": filter})
return response.json()
2021-11-06 20:07:57 +01:00
def add_tasks(self, tasks: list):
"""
Adds tasks to todoist
"""
for task in tasks:
requests.post(self.url + '/tasks',
headers={'Authorization': 'Bearer ' + self.token},
data=json.dumps({
"content": task["content"],
}))