can generate the temp png
This commit is contained in:
parent
1605920d65
commit
a16d472028
@ -82,10 +82,11 @@ class Inkyimage:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def preview(image):
|
def preview(image):
|
||||||
"""Previews an image on gpicview (only works on Rapsbian with Desktop)."""
|
"""Previews an image on gpicview (only works on Rapsbian with Desktop)."""
|
||||||
path = "~/temp"
|
path = "/root/repos/Inkycal/temp"
|
||||||
image.save(path + "/temp.png")
|
image.save(path + "/temp.png")
|
||||||
os.system("gpicview " + path + "/temp.png")
|
print(f"previewing image at {path}/temp.png")
|
||||||
os.system("rm " + path + "/temp.png")
|
# os.system("gpicview " + path + "/temp.png")
|
||||||
|
# os.system("rm " + path + "/temp.png")
|
||||||
|
|
||||||
def _image_loaded(self):
|
def _image_loaded(self):
|
||||||
"""returns True if image was loaded"""
|
"""returns True if image was loaded"""
|
||||||
|
@ -103,6 +103,9 @@ class Todoist(inkycal_module):
|
|||||||
all_active_tasks = self._api.get_tasks()
|
all_active_tasks = self._api.get_tasks()
|
||||||
|
|
||||||
logger.debug(f"all_projects: {all_projects}")
|
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
|
# Filter entries in all_projects if filter was given
|
||||||
if self.project_filter:
|
if self.project_filter:
|
||||||
|
@ -95,16 +95,17 @@ class ApiVikunja():
|
|||||||
if self._cache['projects'] is None:
|
if self._cache['projects'] is None:
|
||||||
self._cache['projects'] = self._get_json(self._create_url('projects'), headers=self._login.get_headers())
|
self._cache['projects'] = self._get_json(self._create_url('projects'), headers=self._login.get_headers())
|
||||||
return self._cache['projects']
|
return self._cache['projects']
|
||||||
|
|
||||||
def get_tasks(self, exclude_completed=True):
|
def get_tasks(self, exclude_completed=True):
|
||||||
if self._cache['tasks'] is None:
|
if self._cache['tasks'] is None:
|
||||||
url = self._create_url('tasks/all')
|
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 []
|
self._cache['tasks'] = self._get_json(url, params, headers=self._login.get_headers()) or []
|
||||||
return self._cache['tasks']
|
return self._cache['tasks']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Todoist(inkycal_module):
|
class Vikunja(inkycal_module):
|
||||||
"""Todoist api class
|
"""Todoist api class
|
||||||
parses todos from the todoist api.
|
parses todos from the todoist api.
|
||||||
"""
|
"""
|
||||||
@ -112,15 +113,18 @@ class Todoist(inkycal_module):
|
|||||||
name = "Vikunja API - show your todos from Vikunja"
|
name = "Vikunja API - show your todos from Vikunja"
|
||||||
|
|
||||||
requires = {
|
requires = {
|
||||||
'api_key': {
|
|
||||||
"label": "Please enter your Todoist API-key",
|
|
||||||
},
|
|
||||||
'url-frontend': {
|
'url-frontend': {
|
||||||
"label": "Please enter your Vikunja URL",
|
"label": "Please enter your Vikunja URL",
|
||||||
},
|
},
|
||||||
'url-backend': {
|
'url-backend': {
|
||||||
"label": "Please enter your Vikunja URL",
|
"label": "Please enter your Vikunja URL",
|
||||||
},
|
},
|
||||||
|
'username': {
|
||||||
|
"label": "Please enter your Vikunja username",
|
||||||
|
},
|
||||||
|
'password': {
|
||||||
|
"label": "Please enter your Vikunja password",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
optional = {
|
optional = {
|
||||||
@ -143,7 +147,6 @@ class Todoist(inkycal_module):
|
|||||||
raise Exception(f'config is missing {param}')
|
raise Exception(f'config is missing {param}')
|
||||||
|
|
||||||
# module specific parameters
|
# module specific parameters
|
||||||
self.api_key = config['api_key']
|
|
||||||
self.frontend_url = config['url-frontend']
|
self.frontend_url = config['url-frontend']
|
||||||
self.backend_url = config['url-backend']
|
self.backend_url = config['url-backend']
|
||||||
|
|
||||||
@ -153,7 +156,8 @@ class Todoist(inkycal_module):
|
|||||||
else:
|
else:
|
||||||
self.project_filter = config['project_filter']
|
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
|
# give an OK message
|
||||||
logger.debug(f'{__name__} loaded')
|
logger.debug(f'{__name__} loaded')
|
||||||
@ -202,18 +206,28 @@ class Todoist(inkycal_module):
|
|||||||
(0, spacing_top + _ * line_height) for _ in range(max_lines)]
|
(0, spacing_top + _ * line_height) for _ in range(max_lines)]
|
||||||
|
|
||||||
# Get all projects by name and id
|
# Get all projects by name and id
|
||||||
all_projects = self._api.get_projects()
|
# all_projects = self._api.get_projects()
|
||||||
filtered_project_ids_and_names = {project.id: project.name for project in all_projects}
|
# filtered_project_ids_and_names = {project.id: project.name for project in all_projects}
|
||||||
all_active_tasks = self._api.get_tasks()
|
# 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_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
|
# Filter entries in all_projects if filter was given
|
||||||
if self.project_filter:
|
if self.project_filter:
|
||||||
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.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['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]
|
filtered_project_ids = [project for project in filtered_project_ids_and_names]
|
||||||
logger.debug(f"filtered projects: {filtered_projects}")
|
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,
|
# If filter was activated and no project was found with that name,
|
||||||
# raise an exception to avoid showing a blank image
|
# 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'
|
'double check spellings in project_filter or leave'
|
||||||
'empty')
|
'empty')
|
||||||
# filtered version of all active tasks
|
# 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
|
# Simplify the tasks for faster processing
|
||||||
simplified = [
|
simplified = [
|
||||||
{
|
{
|
||||||
'name': task.content,
|
'name': task['title'],
|
||||||
'due': arrow.get(task.due.date, "YYYY-MM-DD").format("D-MMM-YY") if task.due else "",
|
'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,
|
'priority': task['priority'],
|
||||||
'project': filtered_project_ids_and_names[task.project_id]
|
'project': filtered_project_ids_and_names[task['project_id']]
|
||||||
}
|
}
|
||||||
for task in all_active_tasks
|
for task in all_active_tasks
|
||||||
]
|
]
|
||||||
|
|
||||||
logger.debug(f'simplified: {simplified}')
|
logger.debug(f'simplified: {simplified}')
|
||||||
|
print(f'simplified: {simplified}')
|
||||||
|
|
||||||
project_lengths = []
|
project_lengths = []
|
||||||
due_lengths = []
|
due_lengths = []
|
||||||
|
@ -2,7 +2,12 @@ import requests
|
|||||||
import json
|
import json
|
||||||
from inkycal.modules.inkycal_vikunja import LoginVikunja
|
from inkycal.modules.inkycal_vikunja import LoginVikunja
|
||||||
from inkycal.modules.inkycal_vikunja import ApiVikunja
|
from inkycal.modules.inkycal_vikunja import ApiVikunja
|
||||||
|
from inkycal.modules.inkycal_vikunja import Vikunja
|
||||||
|
from inkycal.modules.inky_image import Inkyimage
|
||||||
import unittest
|
import unittest
|
||||||
|
from tests import Config
|
||||||
|
preview = Inkyimage.preview
|
||||||
|
merge = Inkyimage.merge
|
||||||
|
|
||||||
class TestLoginVikunja(unittest.TestCase):
|
class TestLoginVikunja(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
@ -25,11 +30,38 @@ class TestApiVikunja(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_projects(self):
|
def test_get_projects(self):
|
||||||
json_projects = self.api.get_projects()
|
json_projects = self.api.get_projects()
|
||||||
print(json_projects)
|
# print(json.dumps(json_projects, indent=4))
|
||||||
self.assertTrue(json_projects)
|
self.assertTrue(json_projects)
|
||||||
|
|
||||||
def test_get_tasks(self):
|
def test_get_tasks(self):
|
||||||
json_tasks = self.api.get_tasks(exclude_completed=True)
|
json_tasks = self.api.get_tasks(exclude_completed=True)
|
||||||
print(json_tasks)
|
print(json.dumps(json_tasks, indent=4))
|
||||||
self.assertTrue(json_tasks)
|
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