Skip to content

Instantly share code, notes, and snippets.

@matteyeux
Created November 26, 2019 15:58
Show Gist options
  • Save matteyeux/8b42a1fcc98c64d4ca318f66a01a0044 to your computer and use it in GitHub Desktop.
Save matteyeux/8b42a1fcc98c64d4ca318f66a01a0044 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from taskw import TaskWarrior
def task_exists(w, task_name: str) -> bool:
"""
check if task exists before inserting it
in Task Warrior.
"""
tasks = w.load_tasks()
for key in tasks.keys():
for task in tasks[key]:
if task['description'] == task_name:
return True
return False
def is_stage_validated(stage: dict) -> bool:
"""
check if stage has special validation key
"""
for key in stage.keys():
if key == "validation":
return True
return False
def add_data_to_taskw(data: dict, module: str):
w = TaskWarrior()
if not task_exists(w, data['name']) and not is_stage_validated(data):
w.task_add(data['name'], project=module)
def add_tasks(wrapper):
"""
add projects and quests
to Task Warrior database
"""
data = json.loads(json.dumps(wrapper.get_current_activities()))
for module in data.keys():
for i in range(len(data[module]['project'])):
print(data[module]['project'][i]['name'], ":", module)
add_data_to_taskw(data[module]['project'][i], module)
for i in range(len(data[module]['quest'])):
for stage in data[module]['quest'][i]['stages']:
print(stage['name'], ":", data[module]['quest'][i]['name'])
if module == "ETN-VIEE":
add_data_to_taskw(stage, module)
else:
add_data_to_taskw(stage, data[module]['quest'][i]['name'])
if __name__ == '__main__':
from etnawrapper import EtnaWrapper
wrapper = EtnaWrapper(login=etna_id, password=etna_passwd)
add_tasks(wrapper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment