Here is the carefree package :)
The python script will open the Birthday.ics file directly from your Owncloud, change the year automaticly and safe the output file at a fixed location. Python “Requests” library is used to connect to your Owncloud.
This script works in linux. The script above was only working in MS Windows.
The script can be run by cron e.g. every 30min so you will see updates and you don’t have to worry about the next year ;)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time functions for current year
import time
from time import localtime, strftime
# Use Requests lib to download Owncloud Birthday calendar .ics file
import requests #http://docs.python-requests.org/en/master/
year = strftime("%Y", localtime()) #Get the current year
try: #Catch errors
url = 'https://YOUR_URL/remote.php/dav/calendars/USER/BIRTHDAYCALENDAR?export' # Url to your Owncloud Birthday caldender .ics file. Replace parts written in capitals
download = requests.get(url, auth=('USER', 'PASS')) #Replace parts written in capitals
fobj_in= download.text.split("\n") #Split file
fobj_out = open("/home/pi/MagicMirror/modules/Birthdays/geburtstage.ics","w") #Output file
for line in fobj_in:
if line.find("DTSTART") > -1 or line.find("DTEND") > -1: #Change year of DTSTART oder DTEND lines
#Format of the string: DTSTART;VALUE=DATE:19650521 #DTEND;VALUE=DATE:19650522
split=line.split(":")
helpline=split[0]+":"+year+split[1][4:]
fobj_out.write(helpline.encode('utf-8')+"\n")
else: #Change nothing, just copy the line
fobj_out.write(line.encode('utf-8')+"\n")
fobj_out.close()
download.close()
except requests.exceptions.RequestException as e: # This is the correct syntax
print(e)