Commit 25a86459 authored by fuzzle's avatar fuzzle

added tacker2ics scripts ... to generate ics files out of a given event-link,...

added tacker2ics scripts ... to generate ics files out of a given event-link, or get upcoming 2 weeks
parent 5b1f79f4
#!/bin/bash
# get a list of event candidates from tacker.fr
# by parsing today+14days
# then write an valid ics file
calendar=./calendar.ics
# empty out calendar.ics if it exists
[ -f "$calendar" ] && rm $calendar
# today and next 14 days
for date in $(seq 0 14)
do
# be dirty and get all headline-level4 links of given date
events=$(curl https://tacker.fr/events/day/$(date --date="+$date day" +%Y%m%d) | grep "<h4".*"/h4>" |grep -o /node/[0-9]* | sed -e 's#^#https://tacker.fr#')
for line in $events
do
echo found $line
# just make a big list
maximizer=$maximizer" $line"
done
done
# ensure we only get each node/event once
# have to take care of strange reoccurings in other ways
# this is otherwise faulty and only first date is added
for mline in $(printf "$maximizer"| tr " " "\n" | sort -u)
do
# use a beatifulsoup4 python script for that
python parse_event_make_ics.py $mline
# add single date ics to bigger one
cat some.ics >> $calendar
done
# delete obsolete begin and end tags
sed -i '/BEGIN:VCALENDAR/d' $calendar
sed -i '/END:VCALENDAR/d' $calendar
# readd vcalendar stuff on top and end
sed -i '1i METHOD:PUBLISH' $calendar
sed -i '1i CALSCALE:GREGORIAN' $calendar
sed -i '1i VERSION:2.0' $calendar
sed -i '1i BEGIN:VCALENDAR' $calendar
echo END:VCALENDAR >> $calendar
echo $calendar file is generated and ready to use
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# parse some tacker.fr event page and generate a
# single ics file out of it
# calendar needed imports
from icalendar import Calendar, Event
from datetime import datetime, timedelta
# parsing needed imports
from bs4 import BeautifulSoup
import sys
import urllib3
# disable warnings from https
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# get url and make r objekt
http = urllib3.PoolManager()
url=sys.argv[1]
r = http.request("GET", url)
# print url
# soup it
soup = BeautifulSoup(r.data, 'html.parser')
# just some feedback
print soup.title.string
#print soup.select_one(".field--name-title").string
print ("#####")
# in general all infos are in article
#print soup.article
# get locationname
# more reliable than the geojson part, which even should be the same
try:
xxlocation = soup.select_one(".field--name-field-location-reference").span.string
except:
xxlocation = "kein Ort angegeben"
#print xxlocation
# get description
# try short-desc first, otherwise only get first part of desc
# which is mostly the first html <p> part
try:
# get short description
xxdesc = soup.select_one(".field--name-field-shortdesc").string
# xxdesc = soup.select_one(".field--type-text-with-summary").p.string
except:
try:
xxdesc = soup.select_one(".field--type-text-with-summary").p.string
except:
xxdesc = "keine Beschreibung"
#print xxdesc
# get repeating rule to add somewhere
try:
xxrep = soup.select_one(".date-recur-repeat-rule").string
except:
xxrep = "non repeating"
# print xxrep
# get begin date
try:
# wdh termine
# xxdate = soup.select_one(".date-recur-occurrences").li.time
# print xxdate
xxdate = soup.time.attrs['datetime']
# should rerun calendar for each datetime stuff
except:
xxdate = soup.time.attrs['datetime']
# get geojson
# often there is geojson coordinates which can be added as geo in ics like
# GEO:48.85299;2.36885
try:
import json
geojson = json.loads(soup.find('script', {'type':'application/json'}).string)
# get some json with
# path:currentPath
# leaflet:leaflet-map:features
# type lat lon popup
geolat = float(geojson['leaflet']['leaflet-map']['features'][0]['lat'])
geolon = float(geojson['leaflet']['leaflet-map']['features'][0]['lon'])
# print geoics
except:
geojson = "keine Geocoordinaten"
# print (geojson['path']['currentPath'])
# geoics = geojson['leaflet']['leaflet-map']['features'][0]['lat']+";"+(geojson['leaflet']['leaflet-map']['features'][0]['lon']))
## calendar magic
cal = Calendar()
event = Event()
event.add('summary', soup.title.string)
event.add('dtstart', datetime.strptime(xxdate, "%Y-%m-%dT%H:%M:%SZ"))
event.add('dtend', (datetime.strptime(xxdate, "%Y-%m-%dT%H:%M:%SZ") + timedelta(hours=1)))
# dtstamp should be "now"
# event.add('dtstamp', datetime(now, "%Y-%m-%dT%H:%M:%SZ"))
event.add('dtstamp', datetime.strptime(xxdate, "%Y-%m-%dT%H:%M:%SZ"))
event.add('description', xxdesc)
event.add('location', "\""+xxlocation+"\"")
# try add GEO Tag
try:
event.add('geo', (geolat, geolon))
except:
print "no geodata (lat,lon) found"
event.add('url', "\""+url+"\"")
# nextcloud need a uid for valid multievent ics files
event.add('uid', "\""+url+"\"")
cal.add_component(event)
f = open('some.ics', 'wb')
f.write(cal.to_ical())
f.close()
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