Skip to content

Instantly share code, notes, and snippets.

@stg7
Created October 21, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stg7/308516ad55070591ba3de55a6c472c56 to your computer and use it in GitHub Desktop.
Save stg7/308516ad55070591ba3de55a6c472c56 to your computer and use it in GitHub Desktop.
a quick and dirty tool for extraction of contacts and calendar entries from an owncloud sqlite3 database to text formats (ics, vcf)
#!/usr/bin/env python3
# a quick and dirty tool for extraction of contacts
# and calendar entries from an owncloud sqlite3 database to text formats (ics, vcf)
#
# run it in your data directory where owncloud.db is stored
import sqlite3
c = sqlite3.connect('owncloud.db')
f = open("calendar-export.ics", "w")
pr = lambda x: f.write(x + "\n")
# dummy vcalender template
# HINT: modify if you are living somewhere else
pr("""\
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//SabreDAV//SabreDAV//EN
CALSCALE:GREGORIAN
X-WR-CALNAME:bla
X-APPLE-CALENDAR-COLOR:#e78074
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
""")
for row in c.execute("SELECT calendardata FROM oc_clndr_objects"):
start_event = False
for l in row[0].split("\n"):
if "BEGIN:VEVENT" in l:
start_event = True
if start_event:
pr(l)
if "END:VEVENT" in l:
start_event = False
pr("END:VCALENDAR")
print("calendar exported")
f.close()
f = open("contacts-export.vcf", "w")
for row in c.execute("SELECT carddata FROM oc_contacts_cards"):
pr(row[0])
f.close()
print("contacts exported")
c.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment