Created
October 21, 2016 21:57
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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