-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_agenda.py
202 lines (176 loc) · 6.14 KB
/
send_agenda.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import requests
import json
import os
from creds import BOT_TOKEN, ROOM_ID
def read_agenda_from_text_file(filename):
with open(filename, "r") as file:
return file.read()
def format_agenda(agenda):
lines = agenda.split("\n")
formatted_agenda = []
for i, line in enumerate(lines):
line = line.strip()
# Add controlled spacing before each line except the first one
if i > 0 and (lines[i - 1].strip() == "" or lines[i - 1].strip() == "- - -"):
formatted_agenda.append(
{
"type": "TextBlock",
"text": " ", # Single space to maintain some spacing
"wrap": True,
"spacing": "none",
}
)
if line == "- - -":
formatted_agenda.append(
{
"type": "TextBlock",
"text": "───────────────────────", # Adjusted line length
"wrap": True,
"spacing": "none",
"color": "light",
}
)
elif line.startswith("! "):
header_text = line[2:].strip()
formatted_agenda.append(
{
"type": "TextBlock",
"text": header_text,
"weight": "bolder",
"size": "medium",
"color": "accent",
"wrap": True,
"spacing": "medium",
}
)
elif line.startswith("$ "):
header_text = line[2:].strip()
formatted_agenda.append(
{
"type": "TextBlock",
"text": header_text,
"weight": "bolder",
"size": "medium",
"color": "warning",
"wrap": True,
"spacing": "medium",
}
)
elif line.startswith("% "):
header_text = line[2:].strip()
formatted_agenda.append(
{
"type": "TextBlock",
"text": header_text,
"weight": "bolder",
"size": "medium",
"color": "attention",
"wrap": True,
"spacing": "medium",
}
)
elif line.startswith("* "):
formatted_agenda.append(
{
"type": "TextBlock",
"text": f"* {line[2:]}", # Adding the bullet marker
"wrap": True,
"spacing": "small",
"color": "attention",
}
)
elif line.startswith("- "):
formatted_agenda.append(
{
"type": "TextBlock",
"text": f"- {line[2:]}", # Adding the bullet marker
"wrap": True,
"spacing": "small",
}
)
elif line.startswith("1. "):
formatted_agenda.append(
{
"type": "TextBlock",
"text": line,
"wrap": True,
"spacing": "small",
}
)
else:
formatted_agenda.append(
{
"type": "TextBlock",
"text": line,
"wrap": True,
"spacing": "small",
}
)
return formatted_agenda
# def save_agenda_to_file(agenda, meeting_name, meeting_date):
# # Create directories if they don't exist
# records_dir = "records"
# meeting_dir = os.path.join(records_dir, meeting_name)
# agendas_dir = os.path.join(meeting_dir, "agendas")
# os.makedirs(agendas_dir, exist_ok=True)
# # Create filename based on meeting name and date with "Agenda" in the name
# filename = f"{meeting_name} {meeting_date} Agenda.txt"
# file_path = os.path.join(agendas_dir, filename)
# with open(file_path, "w") as file:
# file.write(agenda)
def save_message_id(message_id):
with open("message_id.txt", "w") as file:
file.write(message_id)
def send_agenda_to_webex(agenda):
url = "https://webexapis.com/v1/messages"
headers = {
"Authorization": f"Bearer {BOT_TOKEN}",
"Content-Type": "application/json",
}
adaptive_card = {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Meeting Agenda",
"weight": "bolder",
"size": "large",
"color": "good",
}
]
+ format_agenda(agenda),
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
}
payload = {
"roomId": ROOM_ID,
"text": "",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": adaptive_card,
}
],
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
message_id = response.json().get("id")
print(f"Agenda sent successfully!")
save_message_id(message_id)
else:
print(f"Failed to send agenda. Status code: {response.status_code}")
print("Response:", response.json())
if __name__ == "__main__":
agenda_file = "agenda.txt"
meeting_agenda = read_agenda_from_text_file(agenda_file)
# Extract meeting name and date from the first two lines
agenda_lines = meeting_agenda.split("\n")
if len(agenda_lines) >= 2:
meeting_name = agenda_lines[0].strip().lstrip("! ").strip()
meeting_date = agenda_lines[1].strip()
# Save the agenda to a file
# save_agenda_to_file(meeting_agenda, meeting_name, meeting_date)
print("Sending new message...")
send_agenda_to_webex(meeting_agenda)
else:
print("The agenda file does not contain enough lines.")