import argparse import logging import icalendar import datetime import csv from personal_data.util import load_csv_file NOW = datetime.datetime.now(tz = datetime.UTC) def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument('data_folder') parser.add_argument('output_file') return parser.parse_args() def generate_calendar(rows: list[dict]) -> icalendar.Calendar: cal = icalendar.Calendar() cal.add('prodid', '-//personal_data_calendar//example.org//') cal.add('version', '2.0') for event_data in rows: # Select data print(event_data) # Create event event = icalendar.Event() event.add('summary', f'Event {i}') event.add('dtstart', datetime.datetime(2005,4,4,8,0,0,tzinfo=datetime.UTC)) event.add('dtend', datetime.datetime(2005,4,4,10,0,0,tzinfo=datetime.UTC)) event.add('created', NOW) event.add('dtstamp', NOW) cal.add_component(event) del event return cal def main(): args = parse_arguments() dicts = load_csv_file(args.data_folder + '/games_played_playstation.csv') print(dicts) calendar = generate_calendar(dicts) with open(args.output_file, 'wb') as f: f.write(calendar.to_ical()) if __name__ == '__main__': main()