I'm using taskwarrior as a task manager and want to convert task into event for my calender in a .ics
fformat (ICal) using python (ics
package).
if I run the following code:
from ics import Calendar, Event
import json
task1 = {'description': 'blabla', 'scheduled': '20210730T220000Z' }
task2 = {'description': 'blabla', 'scheduled': '2021-07-30T00:00' }
task = task1
if __name__ == "__main__":
c = Calendar()
print(task)
e = Event()
e.name = task['description']
e.begin = task['scheduled']
c.events.add(e)
it throws me an error:
arrow.parser.ParserError: Could not match input to any of ['YYYY-MM-DDTHH:mm'] on '20210730T220000Z'
There is no problem if I replace task = task1
by task = task2
. I suspect that the format of the JSON with timezone is not supported by ics
. Is there an easy way / package to convert 20210730T220000Z
to the format 2021-07-30T00:00
?
Edit N°1 After the comment of @mkrieger1 and the link I tried the following without success:
import datetime
task1 = {'description': 'blabla', 'scheduled': '20210730T220000Z' }
task2 = {'description': 'blabla', 'scheduled': '2021-07-30T00:00' }
print(task1["scheduled"])
dt = datetime.datetime.strptime(task1["scheduled"], 'YYYY-MM-DDTHH:mm').strftime('YYYY-MM-DDTHH:mm')
print(dt)
Edit N°2: this finally worked:
import datetime
task1 = {'description': 'blabla', 'scheduled': '20210730T220000Z' }
task2 = {'description': 'blabla', 'scheduled': '2021-07-30T00:00' }
print(task1["scheduled"])
dt = datetime.datetime.strptime(task1["scheduled"], "%Y%m%dT%H%M%S%fZ")
print(dt)