made script robustly importable as well as callable
This commit is contained in:
parent
ccd9b9673a
commit
ec8d4b9af8
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
@ -6,24 +6,38 @@ import caldav
|
||||
import vobject
|
||||
from datetime import datetime, date, time, timedelta
|
||||
import yaml
|
||||
import os
|
||||
import os, os.path
|
||||
|
||||
|
||||
# find out where events.ini lives; that's the project root dir
|
||||
# check current working directory
|
||||
if os.path.isfile(os.getcwd() + '/events.ini'):
|
||||
project_root = os.getcwd()
|
||||
# check this script's location dir
|
||||
elif os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + '/events.ini'):
|
||||
project_root = os.path.dirname(os.path.realpath(__file__))
|
||||
# check parent dir of this script's dir
|
||||
elif os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + '/../events.ini'):
|
||||
project_root = os.path.dirname(os.path.realpath(__file__)) + '/..'
|
||||
# OK no luck
|
||||
else:
|
||||
print("Cannot find file 'events.ini'; aborting.")
|
||||
exit(1)
|
||||
|
||||
# read ini file
|
||||
print("project_root is %s" % project_root)
|
||||
cp = configparser.ConfigParser()
|
||||
cp.read('../events.ini')
|
||||
cp.read(project_root + '/events.ini')
|
||||
server_url = cp["CalDAV"]["server_url"]
|
||||
cal_url = cp["CalDAV"]["cal_url"]
|
||||
cal_user = cp["CalDAV"]["cal_user"]
|
||||
cal_pass = cp["CalDAV"]["cal_pass"]
|
||||
|
||||
print
|
||||
|
||||
"""Category to filter events for. Only events that belong to this category will be processed."""
|
||||
# Category to filter events for. Only events that belong to this category will be processed.
|
||||
cal_category = "Veranstaltung"
|
||||
"""Name of the file the YAML data will be written to."""
|
||||
result_file = "../content/pages/termine.md"
|
||||
"""List of icalendar properties that will be passed on to Pelican. At this time, all properties are used except those regarding alarms."""
|
||||
# Name of the file the YAML data will be written to.
|
||||
result_file = project_root + '/content/pages/termine.md'
|
||||
# List of icalendar properties that will be passed on to Pelican. At this time, all properties are used except those regarding alarms.
|
||||
cal_properties = [ # taken from ical specification
|
||||
# descriptive
|
||||
"attach", "categories", "class", "comment", "description", "geo", "location", "percent-complete", "priority", "resources", "status", "summary",
|
||||
@ -40,9 +54,9 @@ cal_properties = [ # taken from ical specification
|
||||
# change management
|
||||
"created", "dtstamp", "last-modified", "sequence"
|
||||
]
|
||||
"""List of icalendar properties that the vobject passes as either datetime.datetime or datetime.date objects. To be able to compare any two objects, the script makes each one aware and/or converts into datetime.datetime if necessary. Default timezone is the system timezone; default time is 23:59:59."""
|
||||
#List of icalendar properties that the vobject passes as either datetime.datetime or datetime.date objects. To be able to compare any two objects, the script makes each one aware and/or converts into datetime.datetime if necessary. Default timezone is the system timezone; default time is 23:59:59.
|
||||
cal_prop_datetimes = ["dtend", "due", "dtstart", "duration", "dtstamp", "last-modified"]
|
||||
"""Current time as an aware datetime.datetime object."""
|
||||
# Current time as an aware datetime.datetime object.
|
||||
now = datetime.now().astimezone()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user