generate_seminar_ics.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python3
  2. import uuid
  3. import hashlib
  4. from datetime import datetime
  5. from sys import argv
  6. from prettytable import PrettyTable, HEADER
  7. EVENTS = [
  8. {
  9. "start": "20230526T140000Z",
  10. "end": "20230526T160000Z",
  11. "track": "Math",
  12. "topic": "Elliptic Curves",
  13. "title": "Introduction to Elliptic Curves",
  14. "#": 1,
  15. "recording": "",
  16. },
  17. {
  18. "start": "20230530T140000Z",
  19. "end": "20230530T160000Z",
  20. "track": "Math",
  21. "topic": "Abstract Algebra",
  22. "title": "Group Structure and Homomorphisms",
  23. "#": 1,
  24. "recording": "",
  25. },
  26. {
  27. "start": "20230615T140000Z",
  28. "end": "20230615T160000Z",
  29. "track": "Research",
  30. "topic": "Consensus",
  31. "title": "DarkFi Consensus Algorithm and Control Theory",
  32. "#": 1,
  33. "recording": "",
  34. },
  35. {
  36. "start": "20230622T140000Z",
  37. "end": "20230622T160000Z",
  38. "track": "Dev",
  39. "topic": "Consensus",
  40. "title": "Walkthrough the Consensus code",
  41. "#": 2,
  42. "recording": "",
  43. },
  44. {
  45. "start": "20230629T140000Z",
  46. "end": "20230629T160000Z",
  47. "track": "Dev",
  48. "topic": "Event Graph",
  49. "title": "Walkthrough the Event Graph",
  50. "#": 1,
  51. "recording": "",
  52. },
  53. ]
  54. def print_table():
  55. x = PrettyTable()
  56. x.field_names = ["Date", "Track", "Topic", "#", "Title", "Rec"]
  57. x.align = "l"
  58. x.hrules = HEADER
  59. x.junction_char = "|"
  60. for event in EVENTS:
  61. timestamp = event["start"]
  62. parsed = datetime.strptime(timestamp, "%Y%m%dT%H%M%SZ")
  63. formatted = parsed.strftime("%a %d %b %Y %H:%M UTC")
  64. s = ''.join(ch if ch.isalnum() else '' for ch in event["title"])
  65. ics_file = f"{event['start']}_{s}.ics"
  66. x.add_row([
  67. f"[{formatted}]({ics_file})",
  68. event["track"],
  69. event["topic"],
  70. event["#"],
  71. event["title"],
  72. f"[dl]({event['recording']})",
  73. ])
  74. print("# Developer Seminars\n")
  75. print("Weekly seminars on DarkFi, cryptography, code and other topics.")
  76. print("Each seminar is usually 2 hours long\n")
  77. print(x)
  78. print("\nThe link for calls is")
  79. print("[meet.jit.si/darkfi-seminar](https://meet.jit.si/darkfi-seminar).")
  80. print("\nFor the math seminars, we use a collaborative whiteboard called")
  81. print("[therapy](https://github.com/narodnik/therapy) that we made.")
  82. print("The canvas will also be shared on Jitsi calls.\n")
  83. print("Videos will be uploaded online and linked here.")
  84. print("Join [our chat](https://darkrenaissance.github.io/darkfi/misc/ircd/ircd.html)")
  85. print("for more info. Links and text chat will happen there during the calls.")
  86. def print_ics():
  87. for event in EVENTS:
  88. ics = []
  89. ics.append("BEGIN:VCALENDAR")
  90. ics.append("VERSION:2.0")
  91. ics.append("PRODID:-//dark.fi//Seminars//EN")
  92. ics.append("BEGIN:VEVENT")
  93. ics.append(f"SUMMARY:DarkFi Seminar: {event['title']}")
  94. m = hashlib.md5()
  95. m.update((event["start"] + event["title"]).encode("utf-8"))
  96. ics.append(f"UID:{uuid.UUID(m.hexdigest())}")
  97. ics.append(f"DTSTART:{event['start']}")
  98. ics.append(f"DTEND:{event['end']}")
  99. ics.append(f"DTSTAMP:{event['start']}")
  100. ics.append(f"CATEGORIES:{event['topic']}")
  101. ics.append("URL:https://meet.jit.si/darkfi-seminar")
  102. ics.append("END:VEVENT")
  103. ics.append("END:VCALENDAR")
  104. s = ''.join(ch if ch.isalnum() else '' for ch in event["title"])
  105. ics_file = f"{event['start']}_{s}.ics"
  106. with open(f"book/development/{ics_file}", "w") as f:
  107. f.write('\n'.join(ics))
  108. f.write('\n')
  109. def usage():
  110. print("usage: Use --ics or --table as a flag")
  111. exit(1)
  112. if __name__ == "__main__":
  113. if len(argv) != 2:
  114. usage()
  115. if argv[1] == "--ics":
  116. print_ics()
  117. exit(0)
  118. if argv[1] == "--table":
  119. print_table()
  120. exit(0)
  121. usage()