kopia lustrzana https://github.com/jazzband/icalevents
ci: only run linting in pre-commit
rodzic
ffeef918d9
commit
ff17a9ea67
|
@ -24,10 +24,6 @@ jobs:
|
|||
python -m pip install --upgrade pip
|
||||
pip install pipenv==v2021.5.29
|
||||
pipenv install --dev --deploy
|
||||
- name: Lint with black and flake
|
||||
run: |
|
||||
pipenv run black --check icalevents
|
||||
pipenv run flake8 . --count --exit-zero
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pipenv run coverage run test.py
|
||||
|
|
|
@ -9,7 +9,6 @@ repos:
|
|||
rev: 21.9b0
|
||||
hooks:
|
||||
- id: black
|
||||
args: ['--check', 'icalevents']
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.7.9
|
||||
hooks:
|
||||
|
|
25
docs/conf.py
25
docs/conf.py
|
@ -12,17 +12,18 @@
|
|||
#
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
sys.path.insert(0, os.path.abspath(".."))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'iCalEvents'
|
||||
copyright = '2021, Thomas Irgang'
|
||||
author = 'Thomas Irgang'
|
||||
project = "iCalEvents"
|
||||
copyright = "2021, Thomas Irgang"
|
||||
author = "Thomas Irgang"
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '0.1.25'
|
||||
release = "0.1.25"
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
@ -30,17 +31,15 @@ release = '0.1.25'
|
|||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc'
|
||||
]
|
||||
extensions = ["sphinx.ext.autodoc"]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
templates_path = ["_templates"]
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
@ -48,14 +47,14 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
|||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
html_theme = "alabaster"
|
||||
|
||||
html_theme_options = {
|
||||
# Disable showing the sidebar. Defaults to 'false'
|
||||
'nosidebar': True,
|
||||
"nosidebar": True,
|
||||
}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
html_static_path = ["_static"]
|
||||
|
|
6
main.py
6
main.py
|
@ -1,10 +1,10 @@
|
|||
from icalevents.icalevents import events_async, latest_events, all_done
|
||||
from time import sleep
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
keys = []
|
||||
|
||||
with open('calendars.txt', mode='r', encoding='utf-8') as f:
|
||||
with open("calendars.txt", mode="r", encoding="utf-8") as f:
|
||||
counter = 1
|
||||
|
||||
while True:
|
||||
|
@ -17,7 +17,7 @@ if __name__ == '__main__':
|
|||
url = url.strip()
|
||||
|
||||
fix_apple = False
|
||||
if name == 'icloud':
|
||||
if name == "icloud":
|
||||
fix_apple = True
|
||||
|
||||
key = "req_%d" % counter
|
||||
|
|
52
setup.py
52
setup.py
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
from setuptools import setup
|
||||
|
||||
version = '0.1.25'
|
||||
version = "0.1.25"
|
||||
|
||||
setup(
|
||||
name = 'icalevents',
|
||||
packages = ['icalevents'],
|
||||
name="icalevents",
|
||||
packages=["icalevents"],
|
||||
install_requires=[
|
||||
"httplib2",
|
||||
"icalendar",
|
||||
|
@ -13,27 +13,29 @@ setup(
|
|||
"datetime",
|
||||
],
|
||||
version=version,
|
||||
description = 'iCal downloader and parser',
|
||||
author = 'Thomas Irgang',
|
||||
author_email = 'thomas@irgang-la.de',
|
||||
url = 'https://github.com/jazzband/icalevents',
|
||||
download_url = 'https://github.com/jazzband/icalevents/archive/v' + version + '.tar.gz',
|
||||
keywords = ['iCal'],
|
||||
classifiers = [
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Development Status :: 4 - Beta',
|
||||
'Environment :: Other Environment',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Operating System :: OS Independent',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
],
|
||||
long_description = """\
|
||||
description="iCal downloader and parser",
|
||||
author="Thomas Irgang",
|
||||
author_email="thomas@irgang-la.de",
|
||||
url="https://github.com/jazzband/icalevents",
|
||||
download_url="https://github.com/jazzband/icalevents/archive/v"
|
||||
+ version
|
||||
+ ".tar.gz",
|
||||
keywords=["iCal"],
|
||||
classifiers=[
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Environment :: Other Environment",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Operating System :: OS Independent",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
],
|
||||
long_description="""\
|
||||
iCal download, parse and query tool
|
||||
-------------------------------------
|
||||
|
||||
|
@ -44,5 +46,5 @@ See: icalevents.icalevents.events(url=None, file=None, start=None, end=None, fix
|
|||
|
||||
This version requires Python 3 or later.
|
||||
|
||||
"""
|
||||
""",
|
||||
)
|
||||
|
|
|
@ -6,7 +6,6 @@ import logging
|
|||
|
||||
|
||||
class ICalDownloadTests(unittest.TestCase):
|
||||
|
||||
def test_apple_data_fix(self):
|
||||
data = """
|
||||
DTSTART:18831118T120702
|
||||
|
@ -50,7 +49,7 @@ DTSTART:19180331T020000
|
|||
|
||||
expected = None
|
||||
|
||||
with open(result, mode='r', encoding='utf-8') as f:
|
||||
with open(result, mode="r", encoding="utf-8") as f:
|
||||
expected = f.read()
|
||||
|
||||
content = icalevents.icaldownload.ICalDownload().data_from_file(file)
|
||||
|
@ -63,10 +62,12 @@ DTSTART:19180331T020000
|
|||
|
||||
expected = None
|
||||
|
||||
with open(result, mode='r', encoding='utf-8') as f:
|
||||
with open(result, mode="r", encoding="utf-8") as f:
|
||||
expected = f.read()
|
||||
|
||||
content = icalevents.icaldownload.ICalDownload().data_from_file(file, apple_fix=True)
|
||||
content = icalevents.icaldownload.ICalDownload().data_from_file(
|
||||
file, apple_fix=True
|
||||
)
|
||||
|
||||
self.assertEqual(expected, content, "content form iCal file, google format")
|
||||
|
||||
|
|
|
@ -62,11 +62,19 @@ class ICalEventsTests(unittest.TestCase):
|
|||
|
||||
e1 = evs[1]
|
||||
self.assertEqual(e1.start.hour, 10, "check time with DST")
|
||||
self.assertEqual(e1.start.tzinfo.utcoffset(e1.start), timedelta(seconds=7200), "check UTC offset with DST")
|
||||
self.assertEqual(
|
||||
e1.start.tzinfo.utcoffset(e1.start),
|
||||
timedelta(seconds=7200),
|
||||
"check UTC offset with DST",
|
||||
)
|
||||
|
||||
e2 = evs[2]
|
||||
self.assertEqual(e2.start.hour, 10, "check time without DST")
|
||||
self.assertEqual(e2.start.tzinfo.utcoffset(e2.start), timedelta(seconds=3600), "check UTC offset without DST")
|
||||
self.assertEqual(
|
||||
e2.start.tzinfo.utcoffset(e2.start),
|
||||
timedelta(seconds=3600),
|
||||
"check UTC offset without DST",
|
||||
)
|
||||
|
||||
self.assertEqual(e2.start.day, 5, "Check observance of exdate.")
|
||||
|
||||
|
@ -94,18 +102,27 @@ class ICalEventsTests(unittest.TestCase):
|
|||
self.assertEqual(len(event_set), 1)
|
||||
self.assertEqual(ev.summary, "Recurring All-day Event")
|
||||
self.assertEqual(ev.description, "All-day event recurring on tuesday each week")
|
||||
self.assertTrue(ev.all_day, "Recurring All-day Event's first instance is an all-day event")
|
||||
self.assertTrue(
|
||||
ev.all_day, "Recurring All-day Event's first instance is an all-day event"
|
||||
)
|
||||
|
||||
start_2nd_instance = date(2018, 11, 6)
|
||||
end_2nd_instance = date(2018, 11, 7)
|
||||
|
||||
event_set2 = icalevents.events(url=None, file=ical, start=start_2nd_instance, end=end_2nd_instance)
|
||||
event_set2 = icalevents.events(
|
||||
url=None, file=ical, start=start_2nd_instance, end=end_2nd_instance
|
||||
)
|
||||
ev_2 = event_set2[0]
|
||||
|
||||
self.assertEqual(len(event_set2), 1)
|
||||
self.assertEqual(ev_2.summary, "Recurring All-day Event")
|
||||
self.assertEqual(ev_2.description, "All-day event recurring on tuesday each week")
|
||||
self.assertTrue(ev_2.all_day, "Recurring All-day Event's second instance is an all-day event")
|
||||
self.assertEqual(
|
||||
ev_2.description, "All-day event recurring on tuesday each week"
|
||||
)
|
||||
self.assertTrue(
|
||||
ev_2.all_day,
|
||||
"Recurring All-day Event's second instance is an all-day event",
|
||||
)
|
||||
|
||||
def test_events_rrule_until(self):
|
||||
ical = "test/test_data/rrule_until.ics"
|
||||
|
@ -137,7 +154,9 @@ class ICalEventsTests(unittest.TestCase):
|
|||
end = date(2017, 7, 13)
|
||||
|
||||
ev = icalevents.events(url=None, file=ical, start=start, end=end)[0]
|
||||
self.assertEqual(ev.recurring, False, "check recurring=False for non recurring event")
|
||||
self.assertEqual(
|
||||
ev.recurring, False, "check recurring=False for non recurring event"
|
||||
)
|
||||
|
||||
ical = "test/test_data/recurring.ics"
|
||||
start = date(2018, 10, 15)
|
||||
|
@ -147,8 +166,12 @@ class ICalEventsTests(unittest.TestCase):
|
|||
|
||||
e1 = evs[1]
|
||||
e2 = evs[2]
|
||||
self.assertEqual(e1.recurring, True, "check recurring=True for recurring event (1)")
|
||||
self.assertEqual(e2.recurring, True, "check recurring=True for recurring event (2)")
|
||||
self.assertEqual(
|
||||
e1.recurring, True, "check recurring=True for recurring event (1)"
|
||||
)
|
||||
self.assertEqual(
|
||||
e2.recurring, True, "check recurring=True for recurring event (2)"
|
||||
)
|
||||
|
||||
def test_events_async_url(self):
|
||||
url = "https://raw.githubusercontent.com/jazzband/icalevents/master/test/test_data/basic.ics"
|
||||
|
@ -182,7 +205,15 @@ class ICalEventsTests(unittest.TestCase):
|
|||
end = date(2017, 5, 19)
|
||||
key = "basic"
|
||||
|
||||
icalevents.request_data(key, url=None, file=ical, string_content=None, start=start, end=end, fix_apple=False)
|
||||
icalevents.request_data(
|
||||
key,
|
||||
url=None,
|
||||
file=ical,
|
||||
string_content=None,
|
||||
start=start,
|
||||
end=end,
|
||||
fix_apple=False,
|
||||
)
|
||||
|
||||
self.assertTrue(icalevents.all_done(key), "request is finished")
|
||||
self.assertEqual(len(icalevents.latest_events(key)), 2, "two events are found")
|
||||
|
@ -190,15 +221,22 @@ class ICalEventsTests(unittest.TestCase):
|
|||
def test_string_data(self):
|
||||
ical = "test/test_data/basic.ics"
|
||||
|
||||
with open(ical, mode='rb') as f:
|
||||
with open(ical, mode="rb") as f:
|
||||
string_content = f.read()
|
||||
|
||||
start = date(2017, 5, 18)
|
||||
end = date(2017, 5, 19)
|
||||
key = "basic"
|
||||
|
||||
icalevents.request_data(key, url=None, file=None, string_content=string_content, start=start, end=end,
|
||||
fix_apple=False)
|
||||
icalevents.request_data(
|
||||
key,
|
||||
url=None,
|
||||
file=None,
|
||||
string_content=string_content,
|
||||
start=start,
|
||||
end=end,
|
||||
fix_apple=False,
|
||||
)
|
||||
|
||||
self.assertTrue(icalevents.all_done(key), "request is finished")
|
||||
self.assertEqual(len(icalevents.latest_events(key)), 2, "two events are found")
|
||||
|
@ -213,18 +251,36 @@ class ICalEventsTests(unittest.TestCase):
|
|||
evs = icalevents.events(file=ical, start=start, end=end)
|
||||
|
||||
e1 = evs[0]
|
||||
self.assertIsNotNone(search(r"ended", str(e1.copy_to(n - relativedelta(days=5) + m))), "stringify past event")
|
||||
self.assertIsNotNone(search(r"today", str(e1.copy_to(n - relativedelta(days=1) + m))),
|
||||
"stringify ongoing event")
|
||||
self.assertIsNotNone(search(r"days left", str(e1.copy_to(n + relativedelta(days=3) + m))),
|
||||
"stringify future event")
|
||||
self.assertIsNotNone(
|
||||
search(r"ended", str(e1.copy_to(n - relativedelta(days=5) + m))),
|
||||
"stringify past event",
|
||||
)
|
||||
self.assertIsNotNone(
|
||||
search(r"today", str(e1.copy_to(n - relativedelta(days=1) + m))),
|
||||
"stringify ongoing event",
|
||||
)
|
||||
self.assertIsNotNone(
|
||||
search(r"days left", str(e1.copy_to(n + relativedelta(days=3) + m))),
|
||||
"stringify future event",
|
||||
)
|
||||
|
||||
e2 = evs[1]
|
||||
self.assertIsNotNone(search(r"ended", str(e2.copy_to(n - relativedelta(hours=5)))), "stringify past event")
|
||||
self.assertIsNotNone(search(r"now", str(e2.copy_to(n - relativedelta(hours=1)))), "stringify ongoing event")
|
||||
self.assertIsNotNone(search(r"hours left", str(e2.copy_to(n + relativedelta(hours=3)))),
|
||||
"stringify future event")
|
||||
self.assertIsNotNone(search(r"days left", str(e2.copy_to(n + relativedelta(days=3)))), "stringify future event")
|
||||
self.assertIsNotNone(
|
||||
search(r"ended", str(e2.copy_to(n - relativedelta(hours=5)))),
|
||||
"stringify past event",
|
||||
)
|
||||
self.assertIsNotNone(
|
||||
search(r"now", str(e2.copy_to(n - relativedelta(hours=1)))),
|
||||
"stringify ongoing event",
|
||||
)
|
||||
self.assertIsNotNone(
|
||||
search(r"hours left", str(e2.copy_to(n + relativedelta(hours=3)))),
|
||||
"stringify future event",
|
||||
)
|
||||
self.assertIsNotNone(
|
||||
search(r"days left", str(e2.copy_to(n + relativedelta(days=3)))),
|
||||
"stringify future event",
|
||||
)
|
||||
|
||||
def test_events_no_description(self):
|
||||
ical = "test/test_data/no_description.ics"
|
||||
|
@ -245,10 +301,14 @@ class ICalEventsTests(unittest.TestCase):
|
|||
events = icalevents.events(url=None, file=ical, start=start, end=end)
|
||||
|
||||
self.assertEqual(events[0].created, datetime(2017, 1, 3, 7, 4, 1, tzinfo=UTC))
|
||||
self.assertEqual(events[0].last_modified, datetime(2017, 7, 11, 14, 0, 50, tzinfo=UTC))
|
||||
self.assertEqual(
|
||||
events[0].last_modified, datetime(2017, 7, 11, 14, 0, 50, tzinfo=UTC)
|
||||
)
|
||||
|
||||
self.assertEqual(events[1].created, datetime(2017, 1, 4, 8, 4, 1, tzinfo=UTC))
|
||||
self.assertEqual(events[1].last_modified, datetime(2017, 1, 4, 8, 4, 1, tzinfo=UTC))
|
||||
self.assertEqual(
|
||||
events[1].last_modified, datetime(2017, 1, 4, 8, 4, 1, tzinfo=UTC)
|
||||
)
|
||||
|
||||
self.assertEqual(events[2].created, None)
|
||||
self.assertEqual(events[2].last_modified, None)
|
||||
|
@ -258,5 +318,11 @@ class ICalEventsTests(unittest.TestCase):
|
|||
start = date(2020, 11, 10)
|
||||
end = date(2020, 11, 19)
|
||||
events = icalevents.events(url=None, file=ical, start=start, end=end)
|
||||
self.assertEqual(events[0].categories, ["In19-S04-IT2403"], "event 1 is not equal")
|
||||
self.assertEqual(events[1].categories, ["In19-S04-IT2406", "In19-S04-IT2405"], "event 2 is not equal")
|
||||
self.assertEqual(
|
||||
events[0].categories, ["In19-S04-IT2403"], "event 1 is not equal"
|
||||
)
|
||||
self.assertEqual(
|
||||
events[1].categories,
|
||||
["In19-S04-IT2406", "In19-S04-IT2405"],
|
||||
"event 2 is not equal",
|
||||
)
|
||||
|
|
|
@ -5,12 +5,15 @@ from dateutil.tz import UTC, gettz
|
|||
|
||||
|
||||
class ICalParserTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.eventA = icalevents.icalparser.Event()
|
||||
self.eventA.uid = 1234
|
||||
self.eventA.start = datetime(year=2017, month=2, day=3, hour=12, minute=5, tzinfo=UTC)
|
||||
self.eventA.end = datetime(year=2017, month=2, day=3, hour=15, minute=5, tzinfo=UTC)
|
||||
self.eventA.start = datetime(
|
||||
year=2017, month=2, day=3, hour=12, minute=5, tzinfo=UTC
|
||||
)
|
||||
self.eventA.end = datetime(
|
||||
year=2017, month=2, day=3, hour=15, minute=5, tzinfo=UTC
|
||||
)
|
||||
self.eventA.all_day = False
|
||||
self.eventA.summary = "Event A"
|
||||
self.eventA.attendee = "name@example.com"
|
||||
|
@ -18,15 +21,19 @@ class ICalParserTests(unittest.TestCase):
|
|||
|
||||
self.eventB = icalevents.icalparser.Event()
|
||||
self.eventB.uid = 1234
|
||||
self.eventB.start = datetime(year=2017, month=2, day=1, hour=15, minute=5, tzinfo=UTC)
|
||||
self.eventB.end = datetime(year=2017, month=2, day=1, hour=16, minute=5, tzinfo=UTC)
|
||||
self.eventB.start = datetime(
|
||||
year=2017, month=2, day=1, hour=15, minute=5, tzinfo=UTC
|
||||
)
|
||||
self.eventB.end = datetime(
|
||||
year=2017, month=2, day=1, hour=16, minute=5, tzinfo=UTC
|
||||
)
|
||||
self.eventB.all_day = False
|
||||
self.eventB.summary = "Event B"
|
||||
self.eventB.attendee = ["name@example.com", "another@example.com"]
|
||||
self.eventB.organizer = "name@example.com"
|
||||
|
||||
self.dtA = datetime(2018, 6, 21, 12)
|
||||
self.dtB = datetime(2018, 6, 21, 12, tzinfo=gettz('Europe/Berlin'))
|
||||
self.dtB = datetime(2018, 6, 21, 12, tzinfo=gettz("Europe/Berlin"))
|
||||
|
||||
def test_now(self):
|
||||
n = icalevents.icalparser.now()
|
||||
|
@ -47,16 +54,24 @@ class ICalParserTests(unittest.TestCase):
|
|||
|
||||
self.assertNotEqual(eventC.uid, self.eventA.uid, "new event has new UID")
|
||||
self.assertEqual(eventC.start, new_start, "new event has new start")
|
||||
self.assertEqual(eventC.end - eventC.start, self.eventA.end - self.eventA.start, "new event has same duration")
|
||||
self.assertEqual(
|
||||
eventC.end - eventC.start,
|
||||
self.eventA.end - self.eventA.start,
|
||||
"new event has same duration",
|
||||
)
|
||||
self.assertEqual(eventC.all_day, False, "new event is no all day event")
|
||||
self.assertEqual(eventC.summary, self.eventA.summary, "copy to: summary")
|
||||
self.assertEqual(eventC.description, self.eventA.description, "copy to: description")
|
||||
self.assertEqual(
|
||||
eventC.description, self.eventA.description, "copy to: description"
|
||||
)
|
||||
|
||||
eventD = eventC.copy_to(uid=new_uid)
|
||||
self.assertEqual(eventD.uid, new_uid, "new event has specified UID")
|
||||
self.assertEqual(eventD.start, eventC.start, "new event has same start")
|
||||
self.assertEqual(eventD.end, eventC.end, "new event has same end")
|
||||
self.assertEqual(eventD.all_day, eventC.all_day, "new event is no all day event")
|
||||
self.assertEqual(
|
||||
eventD.all_day, eventC.all_day, "new event is no all day event"
|
||||
)
|
||||
self.assertEqual(eventD.summary, eventC.summary, "copy to: summary")
|
||||
self.assertEqual(eventD.description, eventC.description, "copy to: description")
|
||||
|
||||
|
@ -104,4 +119,4 @@ class ICalParserTests(unittest.TestCase):
|
|||
def test_str(self):
|
||||
self.eventA.start = datetime(year=2017, month=2, day=3, hour=12, minute=5)
|
||||
self.eventA.end = datetime(year=2017, month=2, day=3, hour=15, minute=5)
|
||||
self.assertEqual('2017-02-03 12:05:00+00:00: Event A (ended)', str(self.eventA))
|
||||
self.assertEqual("2017-02-03 12:05:00+00:00: Event A (ended)", str(self.eventA))
|
||||
|
|
Ładowanie…
Reference in New Issue