Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # a quick and dirty tool for extraction of contacts
  3. # and calendar entries from an owncloud sqlite3 database to text formats (ics, vcf)
  4. #
  5. # run it in your data directory where owncloud.db is stored
  6.  
  7. import sqlite3
  8.  
  9. c = sqlite3.connect('owncloud.db')
  10.  
  11. f = open("calendar-export.ics", "w")
  12. pr = lambda x: f.write(x + "\n")
  13.  
  14. # dummy vcalender template
  15. # HINT: modify if you are living somewhere else
  16. pr("""\
  17. BEGIN:VCALENDAR
  18. VERSION:2.0
  19. PRODID:-//SabreDAV//SabreDAV//EN
  20. CALSCALE:GREGORIAN
  21. X-WR-CALNAME:bla
  22. X-APPLE-CALENDAR-COLOR:#e78074
  23. BEGIN:VTIMEZONE
  24. TZID:Europe/Berlin
  25. X-LIC-LOCATION:Europe/Berlin
  26. BEGIN:DAYLIGHT
  27. TZOFFSETFROM:+0100
  28. TZOFFSETTO:+0200
  29. TZNAME:CEST
  30. DTSTART:19700329T020000
  31. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
  32. END:DAYLIGHT
  33. BEGIN:STANDARD
  34. TZOFFSETFROM:+0200
  35. TZOFFSETTO:+0100
  36. TZNAME:CET
  37. DTSTART:19701025T030000
  38. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
  39. END:STANDARD
  40. END:VTIMEZONE
  41. """)
  42. for row in c.execute("SELECT calendardata FROM oc_clndr_objects"):
  43. start_event = False
  44. for l in row[0].split("\n"):
  45. if "BEGIN:VEVENT" in l:
  46. start_event = True
  47.  
  48. if start_event:
  49. pr(l)
  50. if "END:VEVENT" in l:
  51. start_event = False
  52.  
  53.  
  54. pr("END:VCALENDAR")
  55. print("calendar exported")
  56. f.close()
  57.  
  58. f = open("contacts-export.vcf", "w")
  59.  
  60. for row in c.execute("SELECT carddata FROM oc_contacts_cards"):
  61. pr(row[0])
  62.  
  63. f.close()
  64.  
  65. print("contacts exported")
  66.  
  67. c.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement