Commit 040513b6 authored by Henrik Hüttemann's avatar Henrik Hüttemann

Replace urllib with requests to support HTTP Basic Auth.

Signed-off-by: Henrik Hüttemann's avatarHerHde <mail@herh.de>
parent 9af90c34
#!/usr/bin/env python3
""" A Python3 script to fetch iCalendar/ical/ics-feeds from the web and send an email
with upcoming events."""
import urllib.request
from email.message import Message
import smtplib
from datetime import datetime, timedelta, date
from pytz import timezone
from icalendar import Calendar, vDDDTypes
from dateutil import rrule
import requests
import jinja2
import config
......@@ -59,7 +59,7 @@ def format_date(adate):
"time": to_tz_datetime(adate).strftime(config.FORMAT_TIME)
}
def parse_ics(ics_url):
def parse_ics(ics):
"""Parse an ics-file and return the vevents as a list of tuples.
Returns:
......@@ -70,8 +70,18 @@ def parse_ics(ics_url):
1. the duration as a timedelta
of an event.
"""
ics = urllib.request.urlopen(ics_url).read()
cal = Calendar.from_ical(ics)
if isinstance(ics, dict):
response = requests.get(
ics["url"],
auth=requests.auth.HTTPBasicAuth(
ics["username"],
ics["password"]
)
)
else:
response = requests.get(ics)
cal = Calendar.from_ical(response.text)
event_list = []
for event in cal.walk('vevent'):
......
astroid==1.5.3
certifi==2017.7.27.1
chardet==3.0.4
icalendar==3.11.6
idna==2.6
isort==4.2.15
Jinja2==2.9.6
lazy-object-proxy==1.3.1
......@@ -8,5 +11,7 @@ mccabe==0.6.1
pylint==1.7.2
python-dateutil==2.6.1
pytz==2017.2
requests==2.18.4
six==1.10.0
urllib3==1.22
wrapt==1.10.11
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment