Google Calendar iCal - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Google Calendar iCal (/thread-2409.html) |
Google Calendar iCal - Albireo - Mar-14-2017 Hi, I´m currently trying to write a Python-Script that does: - get the .ics file of a certain calendar from Google Calendar - extracts the events in it - writes them to a table in an HTML-file I´m using the module ics 0.3.1 (can´t provide a link here, but it´s one of the first Google results if you search for "python ical"), but I somehow can´t import the calendar. My code: (there are spaces in the used URL, because the software recognizes it as a clickable link, which I am not allowed to post) from ics import Calendar import urllib.request from urllib.request import urlopen url = 'https :// calendar.google.com/ calendar/ ical/ t6l47q578aqr8qjc3pq8cdnfv0%40group.calendar.google.com/ public/ basic.ics' title = 'Test' body_margin = '3em' background = '#eee' header_padding = '1em' article_padding = '2em' def BeginHTML(): print(""" <!doctype html> <html> <head> <meta charset="utf-8"> <title>""" + title + """</title> <style> body {margin: """ + body_margin + """;} header {background: """ + background + """; padding: """ + header_padding + """;} article {padding: """ + article_padding + """;} </style> </head> <body>""") def EndHTML(): print(""" </body> </html>""") try: urllib.request.urlretrieve(url) except urllib.error.HTTPError as err: print(err.code) c = Calendar(urlopen(url).read()) BeginHTML() EndHTML()I get the following error: It would be really great, if there was someone who could help me out, understanding and preferably fixing the error.Thanks in advance! RE: Google Calendar iCal - snippsat - Mar-14-2017 You need to decode to eg to utf-8 when read with in urlopen in Python 3. If not you get byte string back. c = Calendar(urlopen(url).read().decode('utf-8')) Had you used Request then there is no need for decode.Requests is getting correct encoding from web-site. c = Calendar(requests.get(url).text)Same output as over. RE: Google Calendar iCal - Albireo - Mar-15-2017 Thank you very much, this helped a lot. |