can generate the temp png
This commit is contained in:
parent
1605920d65
commit
a16d472028
@ -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"""
|
||||
|
@ -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:
|
||||
|
@ -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 = []
|
||||
|
@ -2,7 +2,12 @@ import requests
|
||||
import json
|
||||
from inkycal.modules.inkycal_vikunja import LoginVikunja
|
||||
from inkycal.modules.inkycal_vikunja import ApiVikunja
|
||||
from inkycal.modules.inkycal_vikunja import Vikunja
|
||||
from inkycal.modules.inky_image import Inkyimage
|
||||
import unittest
|
||||
from tests import Config
|
||||
preview = Inkyimage.preview
|
||||
merge = Inkyimage.merge
|
||||
|
||||
class TestLoginVikunja(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
@ -25,11 +30,38 @@ class TestApiVikunja(unittest.TestCase):
|
||||
|
||||
def test_get_projects(self):
|
||||
json_projects = self.api.get_projects()
|
||||
print(json_projects)
|
||||
# print(json.dumps(json_projects, indent=4))
|
||||
self.assertTrue(json_projects)
|
||||
|
||||
def test_get_tasks(self):
|
||||
json_tasks = self.api.get_tasks(exclude_completed=True)
|
||||
print(json_tasks)
|
||||
print(json.dumps(json_tasks, indent=4))
|
||||
self.assertTrue(json_tasks)
|
||||
|
||||
|
||||
tests = [
|
||||
{
|
||||
"name": "Vikunja",
|
||||
"config": {
|
||||
"size": [400, 1000],
|
||||
"url-frontend": "http://ff.mhrooz.xyz:8077/",
|
||||
"url-backend": "http://192.168.50.10:3456/api/v1/",
|
||||
"username": "iicd",
|
||||
"password": "9297519Mhz.",
|
||||
"project_filter": ["LMU", "Master Thesis"],
|
||||
"padding_x": 10,
|
||||
"padding_y": 10,
|
||||
"fontsize": 12,
|
||||
"language": "en"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
class TestVikunja(unittest.TestCase):
|
||||
def test_generate_image(self):
|
||||
for test in tests:
|
||||
print(f'test {tests.index(test) + 1} generating image..')
|
||||
module = Vikunja(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if Config.USE_PREVIEW:
|
||||
preview(merge(im_black, im_colour))
|
Loading…
Reference in New Issue
Block a user