Created
June 14, 2023 10:58
-
-
Save azmeuk/8baa00eb193feb442e417766d38be260 to your computer and use it in GitHub Desktop.
Populate Getting Things Gnome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import faker | |
import uuid | |
import random | |
fake = faker.Faker() | |
DATASET = "random" | |
NB_TAGS = 0 | |
NB_TASKS = 206 | |
NB_MAX_TAGS_PER_TASK = 0 | |
NB_MAX_SUBTASK_PER_TASK = 0 | |
#STATUSES = ["Active", "Done"] | |
STATUSES = ["Active"] | |
task_ids = [str(uuid.uuid4()) for _ in range(NB_TASKS)] | |
tag_ids = [str(uuid.uuid4()) for _ in range(NB_TAGS)] | |
FILE_TEMPLATE = """<?xml version='1.0' encoding='UTF-8'?> | |
<gtgData appVersion="v0.6-296-gfe121e84" xmlVersion="2"> | |
<taglist> | |
{tag_list} | |
</taglist> | |
<searchlist/> | |
<tasklist> | |
{task_list} | |
</tasklist> | |
</gtgData>""" | |
TAG_TEMPLATE = """ <tag id="{tag_id}" name="{label}" color="{color}"/>""" | |
TASK_TEMPLATE = """ | |
<task id="{task_id}" status="{status}"> | |
<title>{title}</title> | |
<tags> | |
{tag_list} | |
</tags> | |
<dates> | |
<added>{creation_date}</added> | |
<modified>{creation_date}</modified> | |
<recurring_enabled>false</recurring_enabled> | |
</dates> | |
<subtasks> | |
{subtasks_list} | |
</subtasks> | |
<recurring enabled="false"> | |
<term>None</term> | |
</recurring> | |
<content><![CDATA[{content}]]></content> | |
</task> | |
""" | |
tags_rendered = "\n".join( | |
TAG_TEMPLATE.format(tag_id=tag_id, color=fake.color(), label=fake.unique.word()) | |
for tag_id in tag_ids | |
) | |
available_subtasks = list(task_ids) | |
def pick_subtasks(task_id): | |
subtasks = "" | |
if task_id in available_subtasks: | |
available_subtasks.remove(task_id) | |
for _ in range(random.randint(0, NB_MAX_SUBTASK_PER_TASK)): | |
if available_subtasks: | |
random.shuffle(available_subtasks) | |
subtask_id = available_subtasks.pop() | |
subtasks += f"\n <sub>{subtask_id}</sub>" | |
return subtasks | |
task_rendered = "\n".join( | |
TASK_TEMPLATE.format( | |
task_id=task_id, | |
status=random.choice(STATUSES), | |
title=fake.unique.sentence(), | |
creation_date=fake.date_time().isoformat(), | |
content=fake.text(), | |
tag_list="\n ".join( | |
f"<tag>{tag_id}</tag>" | |
for tag_id in random.sample( | |
tag_ids, random.randint(0, NB_MAX_TAGS_PER_TASK) | |
) | |
), | |
subtasks_list=pick_subtasks(task_id), | |
) | |
for task_id in task_ids | |
) | |
with open(f"tmp/{DATASET}/xdg/data/gtg/gtg_data.xml", "w") as fd: | |
fd.write(FILE_TEMPLATE.format(tag_list=tags_rendered, task_list=task_rendered)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment