-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
65 lines (53 loc) · 2.11 KB
/
script.py
File metadata and controls
65 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
This script reads meeting options and associated names
from a CSV file and writes grouped data to a text file.
"""
import csv
def read_meeting_options_csv(filename):
"""
Reads data from a CSV file containing meeting options and associated names.
Args:
filename: The path to the CSV file.
Returns:
A dictionary where keys are meeting options (strings) and values
are lists of unique names (strings) associated with that option.
"""
meeting_options = {}
with open(filename, "r", encoding="utf-8") as csvfile: # Specify encoding
reader = csv.DictReader(csvfile)
for row in reader:
name = row["Name"]
raw_options = (
row["Chosen Meeting Options"].lstrip("[").rstrip("]").split(", ")
)
options = []
for option in raw_options:
option = option.strip().strip("'").strip()
if " " in option:
options.append(option)
meeting_options.setdefault(option, set())
for option in options:
if name not in meeting_options[option]:
meeting_options[option].add(name)
return meeting_options
def write_grouped_data_to_text(data, filename):
"""
Writes grouped meeting options and associated names to a text file.
Args:
data: A dictionary where keys are
meeting options and values are sets of unique names.
filename: The path to the text file.
"""
with open(filename, "w", encoding="utf-8") as textfile: # Specify encoding
for option, names in data.items():
textfile.write(f"**Meeting Option:** {option}\n")
for name in names:
textfile.write(f"- {name}\n")
# Read data from the CSV file
grouped_meeting_options = read_meeting_options_csv("meeting_options.csv")
# Write grouped data to a text file
write_grouped_data_to_text(grouped_meeting_options, "grouped_meeting_options.txt")
print(
"""Grouped meeting options and completely
unique names have been written to 'grouped_meeting_options.txt'."""
)