caldav.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from datetime import datetime
  2. import caldav
  3. from caldav.elements import dav, cdav
  4. # Caldav url
  5. #url = "https://user:pass@hostname/caldav.php/"
  6. class Takvim:
  7. url = "http://kamu:kamu3333@" + "192.168.1.100/bulut/remote.php/caldav/calendars/kamu"
  8. '''vcal = """BEGIN:VCALENDAR
  9. VERSION:2.0
  10. PRODID:-//Example Corp.//CalDAV Client//EN
  11. BEGIN:VEVENT
  12. UID:1234567890
  13. DTSTAMP:20150116T182145Z
  14. DTSTART:20150116T170000Z
  15. DTEND:20150116T180000Z
  16. SUMMARY:pythonla eklenen bir eventtir.
  17. END:VEVENT
  18. END:VCALENDAR
  19. """
  20. '''
  21. vcal = """BEGIN:VCALENDAR
  22. BEGIN:VEVENT
  23. CREATED;VALUE=DATE-TIME:20141130T073450Z
  24. UID:12345aaa99
  25. LAST-MODIFIED;VALUE=DATE-TIME:20141130T073450Z
  26. DTSTAMP;VALUE=DATE-TIME:20141130T073450Z
  27. SUMMARY:BATI LASTIK 4250
  28. DTSTART;VALUE=DATE:20150121
  29. DTEND;VALUE=DATE:20150122
  30. CLASS:PUBLIC
  31. END:VEVENT
  32. END:VCALENDAR
  33. """
  34. def olay_ekle(self,tarih,bilgi):
  35. client = caldav.DAVClient(url)
  36. principal = client.principal()
  37. calendars = principal.calendars()
  38. if len(calendars) > 0:
  39. calendar = calendars[0]
  40. print "Using calendar", calendar
  41. event = calendar.add_event(vcal)
  42. print "Event", event, "created"
  43. def olay_ara(self,tarihbas,tarihson):
  44. client = caldav.DAVClient(url)
  45. principal = client.principal()
  46. calendars = principal.calendars()
  47. if len(calendars) > 0:
  48. calendar = calendars[0]
  49. print "Looking for events in 2015-01"
  50. results = calendar.date_search(
  51. datetime(2015, 1, 1), datetime(2015, 1, 1))
  52. for event in results:
  53. print "Found", event