MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Owncloud integration - Birthday Calendar

    Scheduled Pinned Locked Moved General Discussion
    owncloudbirthdaycalendar
    6 Posts 2 Posters 3.0k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mykle1M Offline
      Mykle1 Project Sponsor Module Developer @STH
      last edited by

      @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!

      Create a working config
      How to add modules

      1 Reply Last reply Reply Quote 0
      • S Offline
        STH
        last edited by STH

        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()
        
        Mykle1M 1 Reply Last reply Reply Quote 1
        • Mykle1M Offline
          Mykle1 Project Sponsor Module Developer @STH
          last edited by

          @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:

          Create a working config
          How to add modules

          1 Reply Last reply Reply Quote 0
          • S Offline
            STH
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • S Offline
              STH
              last edited by STH

              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)
              
              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy