1
0

Fixed title and description

This commit is contained in:
Jon Michael Aanes 2024-08-25 22:15:13 +02:00
parent 72804d145f
commit 28e18fc1b4
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 9 additions and 6 deletions

View File

@ -41,7 +41,10 @@ class PsnProfilesScraper(Scraper):
games_rows = list(self._scrape_games_overview()) games_rows = list(self._scrape_games_overview())
games_ids = {row['psnprofiles.game_id']: row['game.name'] for row in games_rows} games_ids = {row['psnprofiles.game_id']: row['game.name'] for row in games_rows}
SCRAPE_FROM_OVERVIEW = False
if SCRAPE_FROM_OVERVIEW:
yield from games_rows yield from games_rows
idx = 0 idx = 0
for game_id, game_name in games_ids.items(): for game_id, game_name in games_ids.items():
yield from self._scrape_game_trophies(game_id, game_name) yield from self._scrape_game_trophies(game_id, game_name)

View File

@ -17,12 +17,13 @@ def parse_arguments():
def generate_calendar(rows: list[dict]) -> icalendar.Calendar: def generate_calendar(rows: list[dict]) -> icalendar.Calendar:
max_title_parts = 2
cal = icalendar.Calendar() cal = icalendar.Calendar()
cal.add('prodid', '-//personal_data_calendar//example.org//') cal.add('prodid', '-//personal_data_calendar//example.org//')
cal.add('version', '2.0') cal.add('version', '2.0')
for event_data in rows: for event_data in rows:
print(event_data)
# Select data # Select data
possible_time_keys = [ possible_time_keys = [
@ -34,20 +35,20 @@ def generate_calendar(rows: list[dict]) -> icalendar.Calendar:
] ]
date = event_data[possible_time_keys[0]] if possible_time_keys else None date = event_data[possible_time_keys[0]] if possible_time_keys else None
title = event_data[possible_name_keys[0]]
image = event_data[possible_image_keys[0]] if possible_image_keys else None image = event_data[possible_image_keys[0]] if possible_image_keys else None
if date is None: if date is None:
continue continue
description = '\n\n'.join(event_data[k] for k in possible_name_keys) title = ': '.join(event_data[k] for k in possible_name_keys[:max_title_parts])
description = '\n\n'.join(event_data[k] for k in possible_name_keys[max_title_parts:])
# Create event # Create event
event = icalendar.Event() event = icalendar.Event()
event.add('summary', title) event.add('summary', title)
event.add('description', description) event.add('description', description)
event.add('dtstart', date) event.add('dtstart', date)
event.add('dtend', date) event.add('dtend', date + datetime.timedelta(minutes=30))
event.add('created', NOW) event.add('created', NOW)
event.add('dtstamp', NOW) event.add('dtstamp', NOW)
if image: if image:
@ -62,7 +63,6 @@ def main():
args = parse_arguments() args = parse_arguments()
dicts = load_csv_file(args.data_folder + '/games_played_playstation.csv') dicts = load_csv_file(args.data_folder + '/games_played_playstation.csv')
print(dicts)
calendar = generate_calendar(dicts) calendar = generate_calendar(dicts)