pytekukko 0.14.0__py3-none-any.whl → 0.16.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pytekukko/__init__.py CHANGED
@@ -13,7 +13,7 @@ from aiohttp import ClientResponse, ClientResponseError, ClientSession
13
13
  from .exceptions import UnexpectedResponseStructureError
14
14
  from .models import CustomerData, InvoiceHeader, Service
15
15
 
16
- __version__ = "0.14.0"
16
+ __version__ = "0.16.0"
17
17
  DEFAULT_BASE_URL = "https://tilasto.jatekukko.fi/jatekukko/"
18
18
 
19
19
  SERVICE_TIMEZONE = ZoneInfo("Europe/Helsinki")
@@ -4,31 +4,67 @@
4
4
 
5
5
  import asyncio
6
6
  import json
7
+ import sys
8
+ from datetime import datetime, timedelta, timezone
7
9
 
10
+ import icalendar
11
+
12
+ import pytekukko
8
13
  from pytekukko.examples import example_argparser, example_client
9
14
 
10
15
 
11
16
  async def run_example() -> None:
12
17
  """Run the example."""
13
- client, cookie_jar, cookie_jar_path = example_client(
14
- example_argparser(__doc__).parse_args(),
18
+ argparser = example_argparser(__doc__)
19
+ argparser.add_argument(
20
+ "-i", "--icalendar", action="store_true", help="output iCalendar"
15
21
  )
22
+ args = argparser.parse_args()
23
+
24
+ client, cookie_jar, cookie_jar_path = example_client(args)
16
25
 
17
- data = []
18
26
  async with client.session:
19
- services = await client.get_services()
20
- for service in services:
21
- if schedule := await client.get_collection_schedule(service):
22
- data.append( # noqa: PERF401 # negligible, hairy with list comprehension
23
- {
24
- "name": service.name,
25
- "collection_schedule": [x.isoformat() for x in schedule],
26
- },
27
- )
27
+ data = [
28
+ (service, await client.get_collection_schedule(service))
29
+ for service in await client.get_services()
30
+ if service.next_collection
31
+ ]
28
32
  if not cookie_jar_path:
29
33
  await client.logout()
30
34
 
31
- print(json.dumps(data)) # noqa: T201
35
+ if args.icalendar:
36
+ now = datetime.now(tz=timezone.utc)
37
+ cal = icalendar.Calendar()
38
+ cal.add("PRODID", f"pytekukko/{pytekukko.__version__}")
39
+ cal.add("VERSION", "2.0")
40
+ cal.add("NAME", "Jätekukko collections")
41
+ cal.add("X-WR-CALNAME", "Jätekukko collections")
42
+ cal.add("URL", "https://tilasto.jatekukko.fi/indexservice2.jsp")
43
+ cal.add("X-WR-TIMEZONE", "Europe/Helsinki")
44
+ cal.add("METHOD", "PUBLISH")
45
+ for service, schedule in data:
46
+ for date in schedule:
47
+ event = icalendar.Event()
48
+ event.add("UID", f"pytekukko-{service.pos}-{date}@scop.github.io")
49
+ event.add("SUMMARY", service.name)
50
+ event.add("DTSTAMP", now)
51
+ event.add("DTSTART", date)
52
+ event.add("DTEND", date + timedelta(days=1))
53
+ event.add("URL", "https://tilasto.jatekukko.fi/indexservice2.jsp")
54
+ cal.add_component(event)
55
+ sys.stdout.buffer.write(cal.to_ical())
56
+ else:
57
+ print( # noqa: T201 # intentional
58
+ json.dumps(
59
+ [
60
+ {
61
+ "name": service.name,
62
+ "collection_schedule": [date.isoformat() for date in schedule],
63
+ }
64
+ for service, schedule in data
65
+ ]
66
+ )
67
+ )
32
68
 
33
69
  if cookie_jar_path:
34
70
  cookie_jar.save(cookie_jar_path)
@@ -18,8 +18,8 @@ import zoneinfo
18
18
  from collections.abc import Mapping
19
19
  from typing import Any, NamedTuple, cast
20
20
 
21
- from google.oauth2 import service_account # type: ignore[import]
22
- from googleapiclient.discovery import build # type: ignore[import]
21
+ from google.oauth2 import service_account # type: ignore[import-untyped]
22
+ from googleapiclient.discovery import build # type: ignore[import-untyped]
23
23
 
24
24
  from pytekukko.examples import arg_environ_default, example_argparser, example_client
25
25
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytekukko
3
- Version: 0.14.0
3
+ Version: 0.16.0
4
4
  Summary: Jätekukko Omakukko API client
5
5
  Author-email: Ville Skyttä <ville.skytta@iki.fi>
6
6
  License:
@@ -219,10 +219,11 @@ Classifier: Typing :: Typed
219
219
  Requires-Python: >=3.10
220
220
  Description-Content-Type: text/markdown
221
221
  License-File: LICENSE
222
- Requires-Dist: aiohttp (~=3.4)
222
+ Requires-Dist: aiohttp ~=3.4
223
223
  Provides-Extra: examples
224
- Requires-Dist: python-dotenv (<2,>=0.10) ; extra == 'examples'
225
- Requires-Dist: google-api-python-client (>=2.0.2,~=2.0) ; extra == 'examples'
224
+ Requires-Dist: python-dotenv <2,>=0.10 ; extra == 'examples'
225
+ Requires-Dist: google-api-python-client >=2.0.2,~=2.0 ; extra == 'examples'
226
+ Requires-Dist: icalendar ~=5.0 ; extra == 'examples'
226
227
 
227
228
  # pytekukko -- Jätekukko Omakukko API client
228
229
 
@@ -0,0 +1,15 @@
1
+ pytekukko/__init__.py,sha256=lh5p0fm7hE6bK-q_ikFuV-4nLOJIhzD7POfOGmYJQGs,6557
2
+ pytekukko/exceptions.py,sha256=qGxEaKkr6t0ApvOb-_12PjEUwmEZDCMQ4s5BAgde8Og,353
3
+ pytekukko/models.py,sha256=DePgMRUKXkmJVDiXSREVB7JB3Fe7K-tp9Z9VIv0hcIE,2315
4
+ pytekukko/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pytekukko/examples/__init__.py,sha256=okWI6GachxrBvvHR-WElMnzki7Fyq-SB5I35gYUziow,2746
6
+ pytekukko/examples/print_collection_schedules.py,sha256=Qe5X-3iTGpclh_kHdSIaJEpjXVTXw9BTWPEYajj1Ljc,2446
7
+ pytekukko/examples/print_invoice_headers.py,sha256=-yjNMdFyGI6X5eAUFtoy4qO9A4HzaJ7Uz7YO_C_7m6o,947
8
+ pytekukko/examples/print_next_collections.py,sha256=TyxsmQ60zCMOmalIo17YAV9_7yjWSbCYgdZG-ZfOKpU,924
9
+ pytekukko/examples/update_google_calendar.py,sha256=cbFEtRQtsE2EitvkOD5rQZeJAlspqkPD-2AJyS07kog,6706
10
+ pytekukko-0.16.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
11
+ pytekukko-0.16.0.dist-info/METADATA,sha256=ogtbPoHI5YiSq8SSLYurqdM9Ltofr_dPh-HVQRGUONc,16046
12
+ pytekukko-0.16.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
13
+ pytekukko-0.16.0.dist-info/entry_points.txt,sha256=p4qVa_J7SI2g3UoYq9Em_vPBz9DXXzIqL3wpcud2J0o,378
14
+ pytekukko-0.16.0.dist-info/top_level.txt,sha256=CozVPCHdY-e4oxKq01MVWfy3ge_5BlV0I465LUsfchk,10
15
+ pytekukko-0.16.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.0)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,15 +0,0 @@
1
- pytekukko/__init__.py,sha256=58NDCcBYDJspUs4HaYlXiZBVvHboXr-BmZgfO1QorlY,6557
2
- pytekukko/exceptions.py,sha256=qGxEaKkr6t0ApvOb-_12PjEUwmEZDCMQ4s5BAgde8Og,353
3
- pytekukko/models.py,sha256=DePgMRUKXkmJVDiXSREVB7JB3Fe7K-tp9Z9VIv0hcIE,2315
4
- pytekukko/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- pytekukko/examples/__init__.py,sha256=okWI6GachxrBvvHR-WElMnzki7Fyq-SB5I35gYUziow,2746
6
- pytekukko/examples/print_collection_schedules.py,sha256=sHHePPDksh5xZ-R3-BfKq10qYaoHB8z1EsnXCEM4Bg4,1113
7
- pytekukko/examples/print_invoice_headers.py,sha256=-yjNMdFyGI6X5eAUFtoy4qO9A4HzaJ7Uz7YO_C_7m6o,947
8
- pytekukko/examples/print_next_collections.py,sha256=TyxsmQ60zCMOmalIo17YAV9_7yjWSbCYgdZG-ZfOKpU,924
9
- pytekukko/examples/update_google_calendar.py,sha256=AeeMWpmeMfzu5f9ol3t3LKvpHbZ-sfuQ2lT7eMvjrYM,6690
10
- pytekukko-0.14.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
11
- pytekukko-0.14.0.dist-info/METADATA,sha256=CH6GTEFvgGFYZiF1G5xjHoEzWch08jQkTKhDTNXZ_jA,15999
12
- pytekukko-0.14.0.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
13
- pytekukko-0.14.0.dist-info/entry_points.txt,sha256=p4qVa_J7SI2g3UoYq9Em_vPBz9DXXzIqL3wpcud2J0o,378
14
- pytekukko-0.14.0.dist-info/top_level.txt,sha256=CozVPCHdY-e4oxKq01MVWfy3ge_5BlV0I465LUsfchk,10
15
- pytekukko-0.14.0.dist-info/RECORD,,