Battlemesh logo
  • Comments
  • Edit
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
    • Edit SideBar
  • Login

Navigation

  • RecentChanges
  • FindPage
  • PastEvents
  • ContactUs
  • HelpContents
  • attachment:ics-to-moinmoin.py of BattleMeshV15

Attachment 'ics-to-moinmoin.py'

Download

   1 # Copyright (c) 2024 Pedro Vílchez
   2 # SPDX-License-Identifier: AGPL-3.0-or-later
   3 
   4 # With the help of an (AI) LLM, hence, all humanity participated on this
   5 
   6 from icalendar import Calendar, Event
   7 import datetime
   8 
   9 def ics_to_moinmoin_table(ics_file_paths):
  10     events = []
  11     # Define a color mapping for each calendar file
  12     color_map = {
  13         'wbmv15_main.ics':      '#D1D1FF',  # Light blue
  14         'wbmv15_talks.ics':     '#A2D5AB',  # Soft Green
  15         'wbmv15_workshops.ics': '#FFD580',  # Light Orange
  16     }
  17 
  18     # Process each calendar file
  19     for ics_file_path in ics_file_paths:
  20         with open(ics_file_path, 'rb') as file:
  21             cal = Calendar.from_ical(file.read())
  22 
  23         for component in cal.walk():
  24             if component.name == "VEVENT":
  25                 summary = component.get('summary')
  26                 start_dt = component.get('dtstart').dt
  27                 end_dt = component.get('dtend').dt
  28                 description = component.get('description', '-').replace('\n', ' <<BR>> ')
  29 
  30                 event_details = {
  31                     'file': ics_file_path.split('/')[-1],  # Extract filename only
  32                     'start_dt': start_dt,
  33                     'end_dt': end_dt,
  34                     'summary': summary,
  35                     'description': description
  36                 }
  37                 events.append(event_details)
  38 
  39     # Sort events by start date and time
  40     events.sort(key=lambda x: x['start_dt'])
  41 
  42     # Building the MoinMoin table
  43     moinmoin_table = "||'''When'''||'''Title'''||'''Description'''||'''Attachments and links'''||\n"
  44     for event in events:
  45         date_time_str = event['start_dt'].strftime('%Y-%m-%d %H:%M')
  46         if event['start_dt'] != event['end_dt']:
  47             date_time_str += f"-{event['end_dt'].strftime('%H:%M')}"
  48 
  49         # Apply row style based on the event's source file using the color map
  50         row_color = color_map.get(event['file'], '#FFFFFF')  # Default to white if no match
  51         row_style = f"rowstyle=\"background-color: {row_color};\""
  52 
  53         moinmoin_table += f"||<style=\"white-space: nowrap;\" {row_style}>{date_time_str}||{event['summary']}||{event['description']} ||-||\n"
  54 
  55     return moinmoin_table
  56 
  57 def main():
  58     # Example usage with multiple calendar files
  59     #   I used get-ics.sh script too
  60     ics_paths = ['wbmv15_main.ics', 'wbmv15_talks.ics', 'wbmv15_workshops.ics']
  61     wiki_content = ics_to_moinmoin_table(ics_paths)
  62     print(wiki_content)
  63 
  64 if __name__ == "__main__":
  65     main()

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name
tën plüs twö minüs 3?

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2023-05-05 09:17:10, 28.1 KB) [[attachment:APCLogoVectorEN.svg]]
  • [get | view] (2023-05-05 09:17:10, 46.4 KB) [[attachment:Exo.cat-logo.png]]
  • [get | view] (2024-05-22 10:53:36, 577.7 KB) [[attachment:MirageOS.pdf]]
  • [get | view] (2023-05-05 09:28:38, 43.1 KB) [[attachment:RIPE_NCC_Logo2015.png]]
  • [get | view] (2023-05-05 09:58:47, 99.9 KB) [[attachment:Uni_Vienna_Logo_2016.png]]
  • [get | view] (2023-03-28 04:43:26, 39.4 KB) [[attachment:WBMv15-logo-v0.png]]
  • [get | view] (2023-05-05 08:17:30, 93.4 KB) [[attachment:WBMv15-logo-v1.png]]
  • [get | view] (2024-05-17 12:50:44, 5493.0 KB) [[attachment:WBMv15-report.pdf]]
  • [get | view] (2024-05-17 12:44:25, 209.7 KB) [[attachment:WBMv15.pdf]]
  • [get | view] (2023-05-18 02:07:27, 17323.2 KB) [[attachment:WBMv15_chip_wars_2023.pdf]]
  • [get | view] (2023-05-18 02:10:18, 2375.5 KB) [[attachment:WBMv15_testbed_results.pdf]]
  • [get | view] (2024-05-17 12:45:10, 3.3 KB) [[attachment:battlemesh_places_more_compact.r]]
  • [get | view] (2023-01-29 15:08:21, 1965.5 KB) [[attachment:calafou1.jpg]]
  • [get | view] (2023-02-05 14:35:36, 1132.2 KB) [[attachment:calafou2.jpg]]
  • [get | view] (2023-05-09 19:40:10, 69.3 KB) [[attachment:calendar_see_better_titles.png]]
  • [get | view] (2023-05-05 15:04:56, 9.1 KB) [[attachment:ccc-logo.png]]
  • [get | view] (2023-01-29 15:09:54, 1815.2 KB) [[attachment:church1.jpg]]
  • [get | view] (2023-01-29 15:09:59, 2148.0 KB) [[attachment:church2.jpg]]
  • [get | view] (2023-01-29 15:10:04, 881.1 KB) [[attachment:church3.jpg]]
  • [get | view] (2023-01-29 15:12:00, 994.6 KB) [[attachment:communal_area.jpg]]
  • [get | view] (2023-02-05 14:29:36, 518.9 KB) [[attachment:communal_area2.jpg]]
  • [get | view] (2023-05-05 09:17:10, 8.3 KB) [[attachment:freifunk.png]]
  • [get | view] (2023-05-05 09:17:10, 13.5 KB) [[attachment:funkfeuer_logo.png]]
  • [get | view] (2024-05-22 10:49:23, 0.7 KB) [[attachment:get-ics.sh]]
  • [get | view] (2024-05-22 10:53:22, 6.5 KB) [[attachment:gwit-slides.html]]
  • [get | view] (2024-05-22 10:53:27, 3.5 KB) [[attachment:gwit-slides.md]]
  • [get | view] (2023-05-06 10:07:45, 369.2 KB) [[attachment:howtofindcalafou.png]]
  • [get | view] (2024-05-22 10:48:58, 2.4 KB) [[attachment:ics-to-moinmoin.py]]
  • [get | view] (2023-05-05 09:17:10, 8.2 KB) [[attachment:libremesh_logo.png]]
  • [get | view] (2023-05-05 09:17:10, 8.2 KB) [[attachment:libremeshlogo.png]]
  • [get | view] (2023-02-05 14:29:45, 1169.4 KB) [[attachment:main_hall1.jpg]]
  • [get | view] (2023-02-05 14:29:50, 401.8 KB) [[attachment:main_hall2.jpg]]
  • [get | view] (2023-05-05 09:17:10, 24.6 KB) [[attachment:ninuxorglogo.png]]
  • [get | view] (2023-05-06 09:10:05, 66.6 KB) [[attachment:openwisp-logo.png]]
  • [get | view] (2023-05-05 09:51:02, 127.4 KB) [[attachment:qaul-logo-Icon1024.png]]
  • [get | view] (2023-05-05 11:33:38, 9.4 KB) [[attachment:upc-logo.png]]
  • [get | view] (2023-01-29 15:11:46, 1170.8 KB) [[attachment:workshop_space_1.jpg]]
  • [get | view] (2023-01-29 15:11:50, 872.5 KB) [[attachment:workshop_space_2.jpg]]
  • [get | view] (2023-01-29 15:11:55, 926.6 KB) [[attachment:workshop_space_3.jpg]]
 All files | Selected Files: delete move to page copy to page
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01