Owncloud integration - Birthday Calendar



  • Re: OwnCloud integration
    Owncloud calendar integration works fine except for the birthday calendar. Magic Mirror calendar module is not showing the birthdays.
    In the Owncloud Birthday calendar .ics file I found, that the birthday dates are stored with the birth year.
    Example for 22MAY1965
    DTSTART;VALUE=DATE:19650521
    DTEND;VALUE=DATE:19650522

    I assume that the calendar module is only showing entries of the current year.
    Is there a workaround or module existing that could help here?

    Thank you in advance.



  • @STH said in Owncloud integration - Birthday Calendar:

    Example for 22MAY1965
    DTSTART;VALUE=DATE:19650521
    DTEND;VALUE=DATE:19650522

    If it’s a local ics file (or you can download and edit it and save it as a local file) you can change the dates to:
    DTSTART;VALUE=DATE:20170521
    DTEND;VALUE=DATE:20170522
    Then have the calendar module call the local file via your config.js. I’ve done this with other calendars. I think the calendar module doesn’t like dates before 1970.
    Good luck!



  • Hi Mykle1,

    that is a good idea, thank you! I have a workaround now, but I need to change the files every year :(.
    You can download the Birthday .ics from Owncloud and save it localy.
    In the config.js file I changed the calendar url to work with local .ics file:
    url: ‘webcal://localhost:8080/modules/Birthdays/geburtstage_2017.ics’, //Use a local file

    Then I wrote a small python script (for Windows) to change the year of the .ics file, as you proposed above, and it worked.

    If anyone is interessted you can use my python script below. It will open the “geburtstage.ics” file which needs to be located in the same folder as the python script. The script will ask for the year you want to change to and will create a new ics file containing the changed birthday years.

    //your code here

    **Birthday_ICS.py**
    #Ask for the year you want to change to
    year = input("Please enter the year you want to change to: ")
    
    fobj_in = open("geburtstage.ics", "r") #Source file
    fobj_out = open("geburtstage_" + year + ".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)		
    	else: #Change nothing, just copy the line
    		fobj_out.write(line)
    print("Complete!") #Let me know when you are finished
    #Close the documents
    fobj_in.close()
    fobj_out.close()
    


  • @STH said in Owncloud integration - Birthday Calendar:

    Then I wrote a small python script to change the year of the .ics file, as you proposed above, and it worked.

    Oh, well done! :thumbsup:



  • This post is deleted!


  • 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)
    

Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.