aboutsummaryrefslogtreecommitdiff
path: root/script/pull_calendar/pull_event.py
blob: 51b04dcb85c35c9bbc63b8b6b6784ed7f332a541 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import vobject
import wget
import csv
from ics import Calendar, Event

def get_month(month : int):
    match month:
        case 1:
            return "Janvier"
        case 2:
            return "Fevrier"
        case 3:
            return "Mars"
        case 4:
            return "Avril"
        case 5:
            return "Mai"
        case 6:
            return "Juin"
        case 7:
            return "Juillet"
        case 8:
            return "Aout"
        case 9:
            return "Septembre"
        case 10:
            return "Octobre"
        case 11:
            return "Novembre"
        case 12:
            return "Decembre"

if __name__ == "__main__":
    url = "https://sogo.deuxfleurs.fr/SOGo/dav/public/lx/Calendar/22-63E29280-1-71341300.ics"
    filename = wget.download(url)

    # read the data from the file
    data = open(filename).read()

    c = Calendar(data)
    for e in c.events:
        html = "<li role=\"none\"><a href="
        if (e.location is not None and "http" in e.location):
            html += "\"" + e.location + "\""
        else:
            html += "\"#\""
        html += ">"
        html += e.name + "</a> "


        if (e.location is not None and "http" in e.location):
            html += " en ligne"
        elif e.location is not None:
            html += e.location
        html += ","

        html += "<span class=\"highlight\"> le " +  str(e.begin.day) + " " + get_month(e.begin.month) + " " + str(e.begin.year)+  " à "

        if e.begin.hour == 0:
            html +=  "00:"
        else:
            html += str(e.begin.hour) + ":"

        if e.begin.minute == 0:
            html +=  "00 </span>"
        else:
            html += str(e.begin.minute) + "</span>"

        if e.description is not None :
            html += ".<br>" + e.description + "</li>"

        print("\n" + html)