can generate the temp png

This commit is contained in:
2024-08-24 15:03:43 +02:00
parent 1605920d65
commit a16d472028
4 changed files with 74 additions and 23 deletions

View File

@@ -82,10 +82,11 @@ class Inkyimage:
@staticmethod
def preview(image):
"""Previews an image on gpicview (only works on Rapsbian with Desktop)."""
path = "~/temp"
path = "/root/repos/Inkycal/temp"
image.save(path + "/temp.png")
os.system("gpicview " + path + "/temp.png")
os.system("rm " + path + "/temp.png")
print(f"previewing image at {path}/temp.png")
# os.system("gpicview " + path + "/temp.png")
# os.system("rm " + path + "/temp.png")
def _image_loaded(self):
"""returns True if image was loaded"""

View File

@@ -103,6 +103,9 @@ class Todoist(inkycal_module):
all_active_tasks = self._api.get_tasks()
logger.debug(f"all_projects: {all_projects}")
print(f"all_projects: {all_projects}")
logger.debug(f"all_active_tasks: {all_active_tasks}")
print(f"all_active_tasks: {all_active_tasks}")
# Filter entries in all_projects if filter was given
if self.project_filter:

View File

@@ -95,16 +95,17 @@ class ApiVikunja():
if self._cache['projects'] is None:
self._cache['projects'] = self._get_json(self._create_url('projects'), headers=self._login.get_headers())
return self._cache['projects']
def get_tasks(self, exclude_completed=True):
if self._cache['tasks'] is None:
url = self._create_url('tasks/all')
params = {'filter': 'done = false'} if exclude_completed else {}
params = {'filter': 'done=false'} if exclude_completed else {}
self._cache['tasks'] = self._get_json(url, params, headers=self._login.get_headers()) or []
return self._cache['tasks']
class Todoist(inkycal_module):
class Vikunja(inkycal_module):
"""Todoist api class
parses todos from the todoist api.
"""
@@ -112,15 +113,18 @@ class Todoist(inkycal_module):
name = "Vikunja API - show your todos from Vikunja"
requires = {
'api_key': {
"label": "Please enter your Todoist API-key",
},
'url-frontend': {
"label": "Please enter your Vikunja URL",
},
'url-backend': {
"label": "Please enter your Vikunja URL",
},
'username': {
"label": "Please enter your Vikunja username",
},
'password': {
"label": "Please enter your Vikunja password",
},
}
optional = {
@@ -143,7 +147,6 @@ class Todoist(inkycal_module):
raise Exception(f'config is missing {param}')
# module specific parameters
self.api_key = config['api_key']
self.frontend_url = config['url-frontend']
self.backend_url = config['url-backend']
@@ -153,7 +156,8 @@ class Todoist(inkycal_module):
else:
self.project_filter = config['project_filter']
self._api = TodoistAPI(config['api_key'])
# self._api = TodoistAPI(config['api_key'])
self._vikunja_api = ApiVikunja(config['username'], config['password'], None, None, config['url-backend'])
# give an OK message
logger.debug(f'{__name__} loaded')
@@ -202,18 +206,28 @@ class Todoist(inkycal_module):
(0, spacing_top + _ * line_height) for _ in range(max_lines)]
# Get all projects by name and id
all_projects = self._api.get_projects()
filtered_project_ids_and_names = {project.id: project.name for project in all_projects}
all_active_tasks = self._api.get_tasks()
# all_projects = self._api.get_projects()
# filtered_project_ids_and_names = {project.id: project.name for project in all_projects}
# all_active_tasks = self._api.get_tasks()
all_projects = self._vikunja_api.get_projects()
all_active_tasks = self._vikunja_api.get_tasks()
all_active_tasks = [task for task in all_active_tasks if task['done'] == False]
logger.debug(f"all_projects: {all_projects}")
logger.debug(f"all_active_tasks: {all_active_tasks}")
print(f"all_projects: {all_projects}")
print(f"all_active_tasks: {all_active_tasks}")
# Filter entries in all_projects if filter was given
if self.project_filter:
filtered_projects = [project for project in all_projects if project.name in self.project_filter]
filtered_project_ids_and_names = {project.id: project.name for project in filtered_projects}
# filtered_projects = [project for project in all_projects if project.name in self.project_filter]
filtered_projects = [project for project in all_projects if project['title'] in self.project_filter]
filtered_project_ids_and_names = {project['id']: project['title'] for project in filtered_projects}
filtered_project_ids = [project for project in filtered_project_ids_and_names]
logger.debug(f"filtered projects: {filtered_projects}")
print(f"filtered projects: {filtered_projects}")
print(f"filtered_project_ids_and_names: {filtered_project_ids_and_names}")
print(f"filtered_project_ids: {filtered_project_ids}")
# If filter was activated and no project was found with that name,
# raise an exception to avoid showing a blank image
@@ -224,20 +238,21 @@ class Todoist(inkycal_module):
'double check spellings in project_filter or leave'
'empty')
# filtered version of all active tasks
all_active_tasks = [task for task in all_active_tasks if task.project_id in filtered_project_ids]
all_active_tasks = [task for task in all_active_tasks if task['project_id'] in filtered_project_ids]
# Simplify the tasks for faster processing
simplified = [
{
'name': task.content,
'due': arrow.get(task.due.date, "YYYY-MM-DD").format("D-MMM-YY") if task.due else "",
'priority': task.priority,
'project': filtered_project_ids_and_names[task.project_id]
'name': task['title'],
'due': arrow.get(task['due_date']).format("D-MMM-YY") if 'due_date' in task and task['due_date'][:2] != '00' else "",
'priority': task['priority'],
'project': filtered_project_ids_and_names[task['project_id']]
}
for task in all_active_tasks
]
logger.debug(f'simplified: {simplified}')
print(f'simplified: {simplified}')
project_lengths = []
due_lengths = []