選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Supper
  2. Script to generate a seating plan via calendar events in an organisation's Office365.
  3. ## What it does
  4. Supper looks at the current week and generates a seating plan for that week. By getting the calendar of a dedicated room or account, it can see who will be out of the office during the week. It then creates a CSV of who will be in the office on the 5 days of the week.
  5. > **Note:** Current week is defined during the normal workweeks. If the script is run on the weekend (Saturday and Sunday) the script will generate next weeks and label it as such.
  6. ## Requirements
  7. Supper requires:
  8. - Python 3.5 <=
  9. - Admin access to an Org's Office365
  10. > **Warning:** This guide assumes you are using a UNIX based OS (Linux, Mac OS, etc.). If using Windows, god help you.
  11. ## Pre-Install
  12. To setup the script, you will need to create an app in your organisation Azure Active Directory. You can find the app registration page [here](hhttps://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps).
  13. For a guide on how to do this, see the guide provided by python-o365 below.
  14. > To work with OAuth you first need to register your application at [Azure App Registrations](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade).
  15. > 1. Login at [Azure Portal (App Registrations)](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)
  16. > 1. Create an app. Set a name.
  17. > 1. In Supported account types choose "Accounts in any organizational directory.
  18. > 1. Set the redirect uri (Web) to: `https://login.microsoftonline.com/common/oauth2/nativeclient` and click register. This is the default redirect uri used by this library, but you can use any other if you want.
  19. > 1. Write down the Application (client) ID AND Directory (tenant) ID. You will need these values.
  20. > 1. Under "Certificates & secrets", generate a new client secret. Set the expiration to never.
  21. > 1. Write down the value of the client secret created now. It will be hidden later on.
  22. > 1. Under API Permissions add the delegated permissions for Microsoft Graph you want
  23. The required API Permissions are:
  24. ```
  25. Calendars.Read.Shared
  26. User.Read
  27. User.ReadBasic.All
  28. offline_access
  29. ```
  30. ## Installation
  31. Once the app has been created, git clone this repo, cd into its folder and install it into your user's Python PATH.
  32. ```sh
  33. git clone URL
  34. cd supper
  35. python3 -m pip install . --user
  36. ```
  37. This installs the script to your Python user bin.
  38. ## Configuration
  39. ### ID's and Secrets
  40. Now we need to create a config file. This will store all the values we wrote down when creating our application (id, secret, tenant). It will also include some other information that is required to run Supper. This needs to be created by you. Let's create one in the user config folder. This is where Supper will look for a config file by default.
  41. ```sh
  42. touch ~/.config/supper.yaml
  43. ```
  44. This should create an empty YAML file. Open up this file with your text editor of choice and copy and paste this example.
  45. ```yaml
  46. client_id: "CLIENT_ID"
  47. client_secret: "CLIENT_SECRET"
  48. tenant_id: "TENANT_ID"
  49. ooo_email: "example@example.com"
  50. users: ["Bob", "Alice"]
  51. ```
  52. Replace `CLIENT_ID`, `CLIENT_SECRET`, and `TENANT_ID` with the values from the Azure website we wrote down earlier. Replace `ooo_email` with the email of the calendar that has the out of office events. Replace `users` with a list of all the first names of employee's in your organisation. This is case insensitive but has to be spelt the same as their Office365 accounts.
  53. > **Note:** If you are trying to find this file in a file browser and cannot find it, ~/.config is a hidden directory and you will need to enable viewing hidden directories and files in your file browser.
  54. ## Running the program
  55. Now we have configured everything, we can now run the script. To run the script, enter this inside of the terminal.
  56. ```sh
  57. supper
  58. ```
  59. This will generate a `Seating Plan.csv` file in the directory you ran this program. Look at [Output](#output-recommended) to see how to configure the file name of the output.
  60. The first time the script is ran, it will ask you to visit a url. Open the url in your browser and allow the script access to the requested permissions. Once you have done that, you will be redirected to a blank page. Copy the URL and paste it into the console and press enter.
  61. > **Note:** You should login as a user with *full* permissions to the out of office calendar. This is to ensure the script has permissions to view this calendar in full. This will only need to be done every 90 days.
  62. ## Command Arguments
  63. ### Config
  64. If you want to store the config file in a different directory than the default (`/home/$USER/.config/supper.yaml`), you can provide the location of the config file using the `--config` or `-c` flag.
  65. ```sh
  66. supper -c ~/.supper.yaml
  67. ```
  68. ### Output (Recommended)
  69. You can configure the output path too. Normally, the script will output a file called `Seating Plan.csv` in the directory you ran the script in. This can be edited with the `--output` or `-o` flag. We can put the file in a different folder and have a different name like this:
  70. ```sh
  71. supper -c ~/.config/supper.yaml -o "/path/to/file"
  72. ```
  73. For example, we can generate a CSV in our user's Documents folder and name it "Who's in office?"
  74. ```sh
  75. supper -c ~/.config/supper.yaml -o "~/Documents/Who's in office" # If you don't provide a .csv file extension, it will be added for you.
  76. ```
  77. This also supports datetime formatting. This can be done using Python's formatting codes for datetime [which you can find the docs for here.](https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior) When the script is executed, the datetime provided in the string will be set using the start of the weeks date (Monday).
  78. ```sh
  79. supper -c ~/.config/supper.yaml -o "Seating Plan {:%Y-%m-%d}.csv"
  80. ```
  81. This will output a file called `Seating Plan 2019-09-12.csv`
  82. ### Multiple Weeks
  83. The script can output multiple weeks in advance. You can provide a number of weeks in advance with the `-w` or `--weeks` flag.
  84. ```sh
  85. supper -w 2 # Creates three csv's. This week's, and two weeks in advance.
  86. ```
  87. If datetime formatting is provided for the filename, it will give the correct datetime for that files week. Otherwise "_x" will be provided to make sure the script doesn't overwrite itself.
  88. #### Examples
  89. ```sh
  90. supper -o "Seating Plan {:%Y-%m-%d}.csv" -w 2
  91. ```
  92. Will create 3 files named
  93. ```
  94. Seating Plan 2019-10-21.csv
  95. Seating Plan 2019-10-28.csv
  96. Seating Plan 2019-11-04.csv
  97. ```
  98. ---
  99. ```sh
  100. supper -o "Seating Plan.csv" -w 2
  101. ```
  102. Will create 3 files named
  103. ```
  104. Seating Plan.csv
  105. Seating Plan_1.csv
  106. Seating Plan_2.csv
  107. ```
  108. ### Debug
  109. You can enable debug output using the `-d` or `--debug` flags
  110. ## Known Issues
  111. - Long events (longer than a month) may not get picked up in the script as their start dates and end dates may not be in reach of the programs search range.
  112. - Users who do not add themselves as attendees or are not the organisers of their out of office event will not be removed from the output CSV seating plan. This is logged as warnings in the console to make you aware of these events.
  113. - Access tokens are added where the source code is. This might cause issues if the user installs the script as root. Users should use the `--user` tag when installing