generate_seminar_ics.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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": "https://ipfs.io/ipfs/QmRNgGSHjJNSXCnXBF65ThWSSWPyamJi6giBA26uVJrU1W",
  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. if event["recording"] != "":
  67. rec = f"[dl]({event['recording']})"
  68. else:
  69. rec = "n/a"
  70. x.add_row([
  71. f"[{formatted}]({ics_file})",
  72. event["track"],
  73. event["topic"],
  74. event["#"],
  75. event["title"],
  76. rec,
  77. ])
  78. print("# Developer Seminars\n")
  79. print("Weekly seminars on DarkFi, cryptography, code and other topics.")
  80. print("Each seminar is usually 2 hours long\n")
  81. print(x)
  82. print("\nThe link for calls is")
  83. print("[meet.jit.si/darkfi-seminar](https://meet.jit.si/darkfi-seminar).")
  84. print("\nFor the math seminars, we use a collaborative whiteboard called")
  85. print("[therapy](https://github.com/narodnik/therapy) that we made.")
  86. print("The canvas will also be shared on Jitsi calls.\n")
  87. print("Videos will be uploaded online and linked here.")
  88. print("Join [our chat](https://darkrenaissance.github.io/darkfi/misc/ircd/ircd.html)")
  89. print("for more info. Links and text chat will happen there during the calls.")
  90. def print_ics():
  91. for event in EVENTS:
  92. ics = []
  93. ics.append("BEGIN:VCALENDAR")
  94. ics.append("VERSION:2.0")
  95. ics.append("PRODID:-//dark.fi//Seminars//EN")
  96. ics.append("BEGIN:VEVENT")
  97. ics.append(f"SUMMARY:DarkFi Seminar: {event['title']}")
  98. m = hashlib.md5()
  99. m.update((event["start"] + event["title"]).encode("utf-8"))
  100. ics.append(f"UID:{uuid.UUID(m.hexdigest())}")
  101. ics.append(f"DTSTART:{event['start']}")
  102. ics.append(f"DTEND:{event['end']}")
  103. ics.append(f"DTSTAMP:{event['start']}")
  104. ics.append(f"CATEGORIES:{event['topic']}")
  105. ics.append("URL:https://meet.jit.si/darkfi-seminar")
  106. ics.append("END:VEVENT")
  107. ics.append("END:VCALENDAR")
  108. s = ''.join(ch if ch.isalnum() else '' for ch in event["title"])
  109. ics_file = f"{event['start']}_{s}.ics"
  110. with open(f"book/development/{ics_file}", "w") as f:
  111. f.write('\n'.join(ics))
  112. f.write('\n')
  113. def usage():
  114. print("usage: Use --ics or --table as a flag")
  115. exit(1)
  116. if __name__ == "__main__":
  117. if len(argv) != 2:
  118. usage()
  119. if argv[1] == "--ics":
  120. print_ics()
  121. exit(0)
  122. if argv[1] == "--table":
  123. print_table()
  124. exit(0)
  125. usage()