Selection of calendars to download now possible
This commit is contained in:
parent
41e3ff190c
commit
895036ae0c
4 changed files with 78 additions and 47 deletions
|
@ -1 +1,4 @@
|
||||||
# e-inkCal
|
# e-inkCal
|
||||||
|
|
||||||
|
this small script is supposed to be run on a raspberry pi with an SPI e-ink display attached to it.
|
||||||
|
it will then display a weekcalendar on the e-ink display, which is fetched from a calDAV resource.
|
||||||
|
|
9
TODO.md
Normal file
9
TODO.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
ToDo:
|
||||||
|
|
||||||
|
1. catching exceptions for caldav unauthorized
|
||||||
|
2. options:
|
||||||
|
-w show week calendar
|
||||||
|
-m show month calendar
|
||||||
|
|
||||||
|
3. include birthdays from another calendar
|
||||||
|
4. make other views, e.g. month, day, year...
|
|
@ -11,40 +11,44 @@ sys.path.insert(0, './caldav')
|
||||||
import caldav
|
import caldav
|
||||||
from caldav.lib.error import AuthorizationError
|
from caldav.lib.error import AuthorizationError
|
||||||
|
|
||||||
#look for commandline args
|
|
||||||
|
|
||||||
import getopt
|
|
||||||
|
|
||||||
|
|
||||||
inputfile = ''
|
|
||||||
outputfile = ''
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:],"h:i:o",["ifile=","ofile="])
|
|
||||||
except getopt.GetoptError:
|
|
||||||
print('test.py -i <inputfile> -o <outputfile>')
|
|
||||||
sys.exit(2)
|
|
||||||
for opt, arg in opts:
|
|
||||||
if opt == '-h':
|
|
||||||
print ('test.py -i <inputfile> -o <outputfile>')
|
|
||||||
sys.exit()
|
|
||||||
elif opt in ("-i", "--ifile"):
|
|
||||||
inputfile = arg
|
|
||||||
elif opt in ("-o", "--ofile"):
|
|
||||||
outputfile = arg
|
|
||||||
print ('Input file is "', inputfile)
|
|
||||||
print ('Output file is "', outputfile)
|
|
||||||
|
|
||||||
|
|
||||||
|
caldav_url = ''
|
||||||
|
username = ''
|
||||||
|
password = ''
|
||||||
|
datafile = ''
|
||||||
|
selected_cals = []
|
||||||
|
#open config file, load configs
|
||||||
|
configfile = open("./config", "r")
|
||||||
|
conf = configfile.readlines()
|
||||||
|
print(conf)
|
||||||
|
for l in conf:
|
||||||
|
l = l.strip()
|
||||||
|
if(l.startswith("server")):
|
||||||
|
caldav_url = l[7:]
|
||||||
|
elif(l.startswith("user")):
|
||||||
|
username = l[5:]
|
||||||
|
elif(l.startswith("password")):
|
||||||
|
password = l[9:]
|
||||||
|
elif(l.startswith("birthdays")):
|
||||||
|
birthdaycal = l[10:]
|
||||||
|
elif(l.startswith("datafile")):
|
||||||
|
datafile = l[9:]
|
||||||
|
elif(l.startswith("calendars")):
|
||||||
|
selected_cals = l[10:].split(";")
|
||||||
|
print(selected_cals)
|
||||||
|
if(len(caldav_url) == 0):
|
||||||
|
print("Please provide a calDAV link")
|
||||||
|
if(len(username) == 0):
|
||||||
|
print("Please provide a username")
|
||||||
|
|
||||||
#calDAV setup
|
#calDAV setup
|
||||||
caldav_url = 'https://www.kuhl-mann.de/nextcloud/remote.php/dav'
|
|
||||||
username = 'Justus'
|
|
||||||
password = 'Alphabeth1forB2;'
|
|
||||||
timezone = [2,0]
|
timezone = [2,0]
|
||||||
|
|
||||||
timeout = 5
|
timeout = 5
|
||||||
|
|
||||||
f = open("./calendarlib.p")
|
if not (len(datafile) == 0):
|
||||||
|
f = open(datafile)
|
||||||
|
|
||||||
server_reached = True
|
server_reached = True
|
||||||
client_established = True
|
client_established = True
|
||||||
|
@ -58,7 +62,6 @@ except (requests.ConnectionError, requests.Timeout) as exception:
|
||||||
else:
|
else:
|
||||||
print("found server")
|
print("found server")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client = caldav.DAVClient(url=caldav_url, username=username, password=password)
|
client = caldav.DAVClient(url=caldav_url, username=username, password=password)
|
||||||
except (Exception) as ex:
|
except (Exception) as ex:
|
||||||
|
@ -67,8 +70,19 @@ except (Exception) as ex:
|
||||||
if(server_reached and client_established):
|
if(server_reached and client_established):
|
||||||
print("Successfully connected to server, starting to download calendars...")
|
print("Successfully connected to server, starting to download calendars...")
|
||||||
my_principal = client.principal()
|
my_principal = client.principal()
|
||||||
calendars = my_principal.calendars()
|
calendars_fetched = my_principal.calendars()
|
||||||
|
calendars = []
|
||||||
|
if not (len(selected_cals) == 0 or len(selected_cals[0]) == 0):
|
||||||
|
for c in calendars_fetched:
|
||||||
|
if c.name in selected_cals:
|
||||||
|
calendars.append(c)
|
||||||
|
else:
|
||||||
|
calendars = calendars_fetched
|
||||||
|
print("selected calendars:")
|
||||||
|
for c in calendars:
|
||||||
|
print(c.name)
|
||||||
|
|
||||||
|
|
||||||
time_events = []
|
time_events = []
|
||||||
day_events = []
|
day_events = []
|
||||||
birthdays = []
|
birthdays = []
|
||||||
|
@ -105,24 +119,29 @@ if(server_reached and client_established):
|
||||||
"SUMMARY":str(event.vobject_instance.vevent.summary.value),
|
"SUMMARY":str(event.vobject_instance.vevent.summary.value),
|
||||||
"CALENDAR":c.name
|
"CALENDAR":c.name
|
||||||
})
|
})
|
||||||
for event in day_events:
|
if(not (len(birthdaycal) == 0)):
|
||||||
if event["CALENDAR"] == "Geburtstage von Kontakten":
|
for event in day_events:
|
||||||
pieces = event["SUMMARY"].split(" ")
|
if event["CALENDAR"] == birthdaycal:
|
||||||
age = date.today().year - int(pieces[2][2:-1])
|
pieces = event["SUMMARY"].split(" ")
|
||||||
event["SUMMARY"] = pieces[1]+" "+pieces[0][:-1]+" ("+str(age)+")"
|
age = date.today().year - int(pieces[2][2:-1])
|
||||||
birthdays.append(event)
|
event["SUMMARY"] = pieces[1]+" "+pieces[0][:-1]+" ("+str(age)+")"
|
||||||
day_events.remove(event)
|
birthdays.append(event)
|
||||||
|
day_events.remove(event)
|
||||||
print("Download complete")
|
print("Download complete")
|
||||||
calendarlib = {"DAY_EVENTS":day_events,"TIME_EVENTS":time_events,"BIRTHDAYS":birthdays}
|
if(len(datafile)!= 0):
|
||||||
#f = open("./calendarlib.p")
|
calendarlib = {"DAY_EVENTS":day_events,"TIME_EVENTS":time_events,"BIRTHDAYS":birthdays}
|
||||||
p.dump( calendarlib, open( "calendarlib.p", "wb" ))
|
p.dump( calendarlib, open( "calendarlib.p", "wb" ))
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
print("Loading caldata from last time...")
|
if(len(datafile)!= 0):
|
||||||
calendarlib = p.load(open("calendarlib.p","rb"))
|
print("Loading caldata from last time...")
|
||||||
time_events = calendarlib["TIME_EVENTS"]
|
calendarlib = p.load(open("calendarlib.p","rb"))
|
||||||
day_events = calendarlib["DAY_EVENTS"]
|
time_events = calendarlib["TIME_EVENTS"]
|
||||||
birthdays = calendarlib["BIRTHDAYS"]
|
day_events = calendarlib["DAY_EVENTS"]
|
||||||
|
birthdays = calendarlib["BIRTHDAYS"]
|
||||||
|
else:
|
||||||
|
print("No data available!")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
#get principal file
|
#get principal file
|
||||||
|
|
2
config
2
config
|
@ -1,6 +1,6 @@
|
||||||
server:https://www.kuhl-mann.de/nextcloud/remote.php/dav
|
server:https://www.kuhl-mann.de/nextcloud/remote.php/dav
|
||||||
user:Justus
|
user:Justus
|
||||||
password:Alphabeth1forB2;
|
password:Alphabeth1forB2;
|
||||||
datafile:
|
datafile:calendarlib.p
|
||||||
birthdays:Geburtstage von Kontakten
|
birthdays:Geburtstage von Kontakten
|
||||||
calendars:
|
calendars:
|
Loading…
Add table
Add a link
Reference in a new issue