Skip to content

Commit

Permalink
Merge 241a958 into 7d60ac6
Browse files Browse the repository at this point in the history
  • Loading branch information
drinks5 committed Dec 8, 2020
2 parents 7d60ac6 + 241a958 commit 0c80c48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions icalendar_light/toolbox.py
Expand Up @@ -3,8 +3,10 @@
from functools import partial
from pathlib import Path
from typing import Generator, Union, Iterable
import io

from dateutil.tz import tzlocal
import requests

from .casters import cast_date, cast_default, cast_recurrence, cast_int

Expand Down Expand Up @@ -81,6 +83,30 @@ def iter_events_from_file(
with open(f'{filepath}') as f:
yield from func(f)

@classmethod
def iter_events_from_url(
cls,
url: str,
upcoming_days: int = None
) -> Generator[Event, None, None]:
"""Yields event objects from a url.
:param url:
:param upcoming_days:
"""
if upcoming_days is None:
func = cls.iter_events

else:
func = partial(cls.iter_events_upcoming, days_forward=upcoming_days)

response = requests.get(url)
sio = io.StringIO()
sio.write(response.text)
sio.seek(0)
yield from func(sio)

@classmethod
def iter_events(cls, source: Iterable) -> Generator[Event, None, None]:
"""Yields event objects from a given source.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -42,6 +42,7 @@ def get_version():

install_requires=[
'python-dateutil',
'requests'
],
setup_requires=[] + (['pytest-runner'] if 'test' in sys.argv else []) + [],

Expand Down

0 comments on commit 0c80c48

Please sign in to comment.