Skip to content

Instantly share code, notes, and snippets.

@matthew-brett
Created November 25, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthew-brett/8a5dfb629c7cf90b8a8bcfbd79775069 to your computer and use it in GitHub Desktop.
Save matthew-brett/8a5dfb629c7cf90b8a8bcfbd79775069 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Print URL for multi-user teams chat
Start by downloading an attendance sheet in HTML using the ".." icon in the
Attendance interface, and selecting "View Attendance Sheet". This will give
you an HTML file download. Note the filename. Then run this program, passing
the filename of the downloaded file. It will print out a URL you can paste
into your browser. If you do, your browser will open Teams with a chat ready
to fill out, and all the people listed anywhere on the attendance sheet added
(regardless of whether they attended or not).
You can also (optionally) add a title for the Teams chat.
"""
from pathlib import Path
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import pandas as pd
# https://techcommunity.microsoft.com/t5/microsoft-teams/how-to-add-multiple-users-in-teams-chat-in-one-go/m-p/1827194
URL_PREFIX = "https://teams.microsoft.com/l/chat/0/0?users="
def get_parser():
parser = ArgumentParser(description=__doc__, # Usage from docstring
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('attendance_file',
help='Filename for attendance file')
parser.add_argument('--chat-name',
help='Name for chat')
return parser
def main():
parser = get_parser()
args = parser.parse_args()
afile = Path(args.attendance_file).expanduser()
tables = pd.read_html(afile)
if not tables:
raise RuntimeError(f'No table in {afile}')
if len(tables) > 1:
raise RuntimeError(f'More than one table in {afile}')
df = tables[0]
if 'Email' not in df:
raise RuntimeError(f'No "Email" column in table from {afile}')
out = URL_PREFIX + ','.join(df['Email'])
if args.chat_name:
out += "&topicName=" + args.chat_name
print(out)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment