1
0
This commit is contained in:
Jon Michael Aanes 2024-08-25 20:50:03 +02:00
parent aebf3c7df4
commit 595640efdf
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
5 changed files with 44 additions and 27 deletions

View File

@ -71,7 +71,11 @@ def has_data_attribute(e) -> bool:
def normalize_soup_slightly(
soup, classes=True, scripts=True, comments=True, data_attributes=True,
soup,
classes=True,
scripts=True,
comments=True,
data_attributes=True,
):
"""Perform soup normalization."""
# Little if any content

View File

@ -1,18 +1,12 @@
import csv
import datetime
import decimal
import inspect
import io
from pathlib import Path
import logging
from collections.abc import Iterable, Mapping, Sequence
from decimal import Decimal
from collections.abc import Sequence
from pathlib import Path
import requests
import requests_cache
from frozendict import frozendict
from . import notification, data
from . import data, notification
from .util import *
logger = logging.getLogger(__name__)

View File

@ -31,7 +31,8 @@ def parse_duration(text: str) -> datetime.timedelta:
def parse_response_datetime(response) -> datetime.datetime:
return datetime.datetime.strptime(
response.headers['Date'], FORMAT_DATE_HEADER,
response.headers['Date'],
FORMAT_DATE_HEADER,
).replace(tzinfo=datetime.UTC)

View File

@ -2,13 +2,13 @@ import csv
import datetime
import decimal
import io
import urllib.parse
from pathlib import Path
import logging
from collections.abc import Iterable, Mapping, Sequence, Callable
from decimal import Decimal
import typing
import urllib.parse
from collections.abc import Callable, Iterable, Mapping, Sequence
from decimal import Decimal
from pathlib import Path
from frozendict import frozendict
from . import data
@ -20,6 +20,7 @@ csv.register_dialect(CSV_DIALECT, lineterminator='\n', skipinitialspace=True)
T = typing.TypeVar('T')
def try_value(fn: Callable[[str], T], s: str) -> T | None:
try:
return fn(s)
@ -27,7 +28,17 @@ def try_value(fn: Callable[[str],T], s: str) -> T | None:
return None
def to_value(s: str) -> str | Decimal | datetime.date | datetime.datetime | urllib.parse.ParseResult | bool | None:
def to_value(
s: str,
) -> (
str
| Decimal
| datetime.date
| datetime.datetime
| urllib.parse.ParseResult
| bool
| None
):
s = s.strip()
if len(s) == 0:
return None
@ -139,6 +150,7 @@ def load_csv_file(csv_file: Path) -> list[frozendict]:
del csvfile
return dicts
def extend_csv_file(
csv_file: Path,
new_dicts: list[dict],

View File

@ -1,20 +1,21 @@
import argparse
import logging
import icalendar
import urllib.parse
import datetime
import csv
import urllib.parse
import icalendar
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//')
@ -24,9 +25,13 @@ def generate_calendar(rows: list[dict]) -> icalendar.Calendar:
print(event_data)
# Select data
possible_time_keys = [k for k,v in event_data.items() if isinstance(v, datetime.date)]
possible_time_keys = [
k for k, v in event_data.items() if isinstance(v, datetime.date)
]
possible_name_keys = [k for k, v in event_data.items() if isinstance(v, str)]
possible_image_keys = [k for k,v in event_data.items() if isinstance(v, urllib.parse.ParseResult)]
possible_image_keys = [
k for k, v in event_data.items() if isinstance(v, urllib.parse.ParseResult)
]
date = event_data[possible_time_keys[0]] if possible_time_keys else None
title = event_data[possible_name_keys[0]]
@ -64,5 +69,6 @@ def main():
with open(args.output_file, 'wb') as f:
f.write(calendar.to_ical())
if __name__ == '__main__':
main()