Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Google Calendar iCal
#1
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:

Error:
Traceback (most recent call last):   File "ical_test.py", line 38, in <module>     c = Calendar(urlopen(url).read())   File "//anaconda/lib/python3.5/site-packages/ics/icalendar.py", line 62, in __init__     container = lines_to_container(imports)   File "//anaconda/lib/python3.5/site-packages/ics/parse.py", line 162, in lines_to_container     return parse(tokenize_line(unfold_lines(lines)))   File "//anaconda/lib/python3.5/site-packages/ics/parse.py", line 153, in parse     for line in tokenized_lines:   File "//anaconda/lib/python3.5/site-packages/ics/parse.py", line 147, in tokenize_line     for line in unfolded_lines:   File "//anaconda/lib/python3.5/site-packages/ics/parse.py", line 132, in unfold_lines     if len(line.strip()) == 0: AttributeError: 'int' object has no attribute 'strip'
It would be really great, if there was someone who could help me out, understanding and preferably fixing the error.

Thanks in advance!
Reply


Messages In This Thread
Google Calendar iCal - by Albireo - Mar-14-2017, 12:02 PM
RE: Google Calendar iCal - by snippsat - Mar-14-2017, 03:40 PM
RE: Google Calendar iCal - by Albireo - Mar-15-2017, 03:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Online calendar for booking. SpongeB0B 6 3,621 Nov-15-2023, 11:27 AM
Last Post: Woki
  Follow Up: Web Calendar based Extraction AgileAVS 0 1,530 Feb-23-2020, 05:39 AM
Last Post: AgileAVS
  Extracting Data from Calendar AgileAVS 2 3,790 Feb-16-2020, 01:06 PM
Last Post: AgileAVS
  Google calendar pthon flask auth Kireta 0 2,133 Sep-16-2019, 04:50 PM
Last Post: Kireta

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020