-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypo3-activity-indicator.py
67 lines (56 loc) · 2.53 KB
/
typo3-activity-indicator.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
# Copyright (C) 2022 Patrick Pedersen, TUDO Makerspace
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Author: Patrick Pedersen <[email protected]>
# Usage: Run typo3-acitivty-indicator.py --help
# Brief Description:
# Updates the activity status on a TYPO3 website with the Activity Indicator extension
# Description:
# The following script is used to update the Activity status on a TYPO3 website with
# the Activity Indicator extension (github.com/TU-DO-Makerspace/TYPO3-ActivityIndicator)
# installed.
#
# The TYPO3 Activity Indicator extension exposes the following REST API endpoints to set
# and retrieve the Activity status:
#
# - GET /api/ActivityIndicator/activity (returns the current activity status)
# - POST /api/ActivityIndicator/activity/{open|closed} (sets the activity status and requires HTTP Basic Auth)
#
# Only a FE user of the API group can use the POST endpoint to set the activity status, hence the
# credentials for one must be provided in the typo3.ini configuration file.
import argparse
import configparser
import requests
# POST endpoint to set the activity status
POST_ENDPOINT = '/api/ActivityIndicator/activity/'
# Parse arguments
parser = argparse.ArgumentParser(description='Updates the activity status on a TYPO3 website with the Activity Indicator extension')
parser.add_argument('--config_file', '-c', help='Config file', default='typo3.ini')
parser.add_argument(
'activity',
choices=['open', 'closed'],
help='Activity status'
)
args = parser.parse_args()
# Read config file
config = configparser.ConfigParser()
config.read(args.config_file)
uname = config['api']['Username']
pwd = config['api']['Password']
url = config['api']['URL']
# Send POST request to set the activity status
response = requests.post(
url + POST_ENDPOINT + args.activity,
auth=(uname, pwd)
)
# Print error message if POST request failed
if response.status_code != 200:
print("typo3-activity-indicator.py: Request Failed: " + response.text)