daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Apr 19th, 2015 582 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import md5
  3.  
  4. print "--- oase2ics ---"
  5. print "opening CSV file..."
  6. rawData = open(sys.argv[1]).readlines()
  7. print "importing",len(rawData),"appointments"
  8. outputIcs = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//oase2ics//NONSGML v1.0//EN\n"
  9. rawData.pop(0)
  10. for item in rawData:
  11.     itemParts = item.split(",")
  12.     outputIcs = outputIcs + "BEGIN:VEVENT\n"
  13.     outputIcs = outputIcs + "UID:" + md5.new(item).hexdigest() + "\n"
  14.     startTimeHour = itemParts[2].replace(" ", "").split(":")[0]
  15.     startTimeHour = str((int(startTimeHour[0:2])-2)) + startTimeHour[2:]
  16.     if len(startTimeHour) == 1:
  17.         startTimeHour = "0" + startTimeHour
  18.     startTimeMinute = itemParts[2].replace(" ", "").split(":")[1]
  19.     outputIcs = outputIcs + "DTSTAMP:" + itemParts[0].replace("-", "") + "T" + startTimeHour + startTimeMinute + "00Z\n"
  20.     outputIcs = outputIcs + "DTSTART:" + itemParts[0].replace("-", "") + "T" + startTimeHour + startTimeMinute + "00Z\n"
  21.     endTimeHour = itemParts[3].replace(" ", "").split(":")[0]
  22.     endTimeHour = str((int(endTimeHour[0:2])-2)) + endTimeHour[2:]
  23.     if len(endTimeHour) == 1:
  24.         endTimeHour = "0" + endTimeHour
  25.     endTimeMinute = itemParts[3].replace(" ", "").split(":")[1]
  26.     outputIcs = outputIcs + "DTEND:" + itemParts[0].replace("-", "") + "T" + endTimeHour + endTimeMinute + "00Z\n"
  27.     summary = itemParts[5]
  28.     if "Uren" in summary:
  29.         summary = summary.split("Uren")[0]
  30.     if "Sluitingsdatum" in summary:
  31.         summary = summary.split("Sluitingsdatum")[0]
  32.     outputIcs = outputIcs + "SUMMARY:" + summary[1:6] + " - " + summary[7:-1] + "\n"
  33.     outputIcs = outputIcs + "LOCATION:" + itemParts[4] + "\n"
  34.     outputIcs = outputIcs + "END:VEVENT\n"
  35. outputIcs = outputIcs + "END:VCALENDAR"
  36. newFilePath = sys.argv[1].replace(".csv", ".ics")
  37. outputFile = open(newFilePath, "w")
  38. outputFile.write(outputIcs)
  39. outputFile.close()
  40. print "done, ICS generated"
RAW Paste Data
Top