summaryrefslogtreecommitdiff
path: root/scripts/icstocal
diff options
context:
space:
mode:
authormarcellus <msimon_fr@hotmail.com>2023-04-26 14:51:54 +0200
committermarcellus <msimon_fr@hotmail.com>2023-04-26 15:00:27 +0200
commitf4960863d3aa0604490e7ee758d8725f029c3805 (patch)
tree9681946e1feb48b8010c81c4252f58c09eced870 /scripts/icstocal
parentb0ae0d055deac58ff601ff03bb9338efe547e064 (diff)
fix: patched the PATH, added a wallpaper, added dwmblocks config file
Diffstat (limited to 'scripts/icstocal')
-rwxr-xr-xscripts/icstocal99
1 files changed, 99 insertions, 0 deletions
diff --git a/scripts/icstocal b/scripts/icstocal
new file mode 100755
index 0000000..94e8700
--- /dev/null
+++ b/scripts/icstocal
@@ -0,0 +1,99 @@
+#!/usr/bin/env python3
+# A really poorly written script to convert .ics file to calendar file for quand or when
+# doesn't work when an event take longer than a day
+
+from sys import argv
+from pathlib import Path
+
+if len(argv) < 3:
+ print("To use this script you need to supply 2 arguments.")
+ print("e.g.: icsparser calendar.ics $XDG_DATA_HOME/quand/calendar")
+ exit()
+
+TIMEZONE = 2 # as UTC+2
+IN="en" # 'en' means 'in' in french
+INPUT = argv[1]
+OUTPUT = argv[2]
+
+if not Path(INPUT).is_file():
+ print("{0} doesn't exist".format(INPUT))
+ exit()
+
+file = open(INPUT, "r")
+
+if file.readline() != "BEGIN:VCALENDAR\n":
+ print("{0} is not valid".format(INPUT))
+ file.close()
+ exit()
+
+line = file.readline()
+locations = []
+summaries = []
+starts = []
+ends = []
+
+while line != "END:VCALENDAR\n":
+ if line == "BEGIN:VEVENT\n":
+ while line != "END:VEVENT\n":
+ if line.startswith("LOCATION"):
+ locations.append(line[9:].strip())
+ elif line.startswith("SUMMARY"):
+ summaries.append(line[8:].strip())
+ elif line.startswith("DTSTART"):
+ start = line.lstrip("DTSTART")
+ year = ""
+ month = ""
+ day = ""
+ hour = ""
+ min = ""
+ for i in range(len(start)):
+ if i >= 1 and i <= 4:
+ year += start[i]
+ elif i == 5 or i == 6:
+ month += start[i]
+ elif i == 7 or i == 8:
+ day += start[i]
+ elif i == 10:
+ hour += start[i]
+ elif i == 11:
+ if int(start[i]) + TIMEZONE > 9:
+ hour = str(int(hour[0]) + 1) + "0" # I cba do the case where H will become 25
+ else:
+ hour += str(int(start[i]) + TIMEZONE)
+ elif i == 12 or i == 13:
+ min += start[i]
+ starts.append([year, month, day, hour, min])
+ elif line.startswith("DTEND"):
+ end = line.lstrip("DTEND")
+ hour = ""
+ min = ""
+ for i in range(len(end)):
+ if i == 10:
+ hour += end[i]
+ elif i == 11:
+ if int(end[i]) + TIMEZONE > 9:
+ hour = str(int(hour[0]) + 1) + "0" # I cba do the case where H will become 25
+ else:
+ hour += str(int(end[i]) + TIMEZONE)
+ elif i == 12 or i == 13:
+ min += end[i]
+ ends.append("{0}:{1}".format(hour, min))
+ line = file.readline()
+ line = file.readline()
+file.close()
+
+file = open(OUTPUT, "w")
+for i in range(len(locations)):
+ # yyyy mm dd, hh:hh -> hh:hh summary location
+ file.write("{0} {1} {2}, {3}:{4} -> {5} {6} {7} {8}\n".format(starts[i][0],
+ starts[i][1],
+ starts[i][2],
+ starts[i][3],
+ starts[i][4],
+ ends[i],
+ summaries[i],
+ IN,
+ locations[i]))
+
+file.close()
+print("All done!")