bensteuem / churchtoolsapi Goto Github PK
View Code? Open in Web Editor NEWCollection of Python files to use the API for ChurchTools
Collection of Python files to use the API for ChurchTools
at present only the status code is checked and json.loads can fail (e.g. if not authorized)
if response.status_code == 200:
csrf_token = json.loads(response.content)["data"]
The method should "try" json.loads and return the error message from the html document in case it fails.
This might also apply to other requests!
Issue created when running WebService with
session['ct_api'] = CTAPI(domain, ct_user=user, ct_password=password)
which then calls
login_ct_ajax_api
https://github.com/bensteUEM/ChurchToolsAgendaZuWord
is currently a desktop app, merge it into this project and offer download using web UI
Method has been implemented with ID only but allows for more search params in API
Include @kolibri52 and @bensteUEM as authors in code readme ...
Integrating #66 resulted in recurring dependency problems because CommuniAPI requires an older version of ChurchToolsApi which in itself requires an older version of CommuniAPI
By splitting the WebUI / Docker part from the REST API itself the dependencies will be easier to resolve.
In addition the requirement should to be changed in order to require a minimum version instead of a fixed version if possible
Missing info text for filename param - could be name of the file to lookup or the name of the file to be saved ...
Also missing datatypes in docstring
test_get_events() should see a warning
logging.warning('Use of from is only allowed together with from')
logging.warning('Use of limit is only allowed together with direction keyword')
if params are incorrect - there is a stub in the test method with assertLogs but the warning is not detected
error is
AssertionError: no logs of level WARNING or higher triggered on root
likely impropper use of logging...
2023-02-20 18:29:14,552 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /api/events?from=2023-02-06&to=2023-02-20 HTTP/1.1" 200 None
2023-02-20 18:29:14,557 root DEBUG First response of Events successful {'data': [{'id': 2469, 'guid': '5EB6E113-2638-4FEB-
[...]
2023-02-20 18:29:14,650 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /api/events/%7B'id':%202469,%20'guid':%20'5EB6E113-2638-4FEB-9BCA-E40BCC22AA07',%20'name':%20'Kaminabend',%20'description':%20'',%20'appointmentId':%20326169,%20'startDate':%20'2023-02-09T18:30:00Z',%20'endDate':%20'2023-02-09T21:00:00Z',%20'chatStatus':%20'NOT_STARTED',%20'isCanceled':%20False,%20'permissions':%20%7B'useChat':%20False,%20'startChat':%20False%7D,%20'calendar':%20%7B'title':%20'Sonstige%20Veranstaltung',%20'domainType':%20'calendar',%20'domainIdentifier':%20'1',%20'apiUrl':%20'',%20'frontendUrl':%20'',%20'imageUrl':%20'',%20'icon':%20'calendar',%20'domainAttributes':%20%7B'campusName':%20None%7D%7D,%20'eventFiles':%20%5B%5D%7D HTTP/1.1" 400 None
2023-02-20 18:29:14,653 root WARNING Something went wrong fetching events: 400
This looks like a request is made using the event content instead of an ID
Write a simple web-server function that allows CT login and displays some information from the API
Followup of #43 within
def events():
the file should be deleted after successful download
At present Communi Login is only displayed after successful login - it should also be shown if a previous login does exist and API is already useable due to session.
Implementation slightly differs from CT API because no whoAmI() exists in Communi - might be required to add that to API first...
function returns response item - can this be changes to response['data'] instead?
def edit_song(self, song_id: int, songcategory_id=None, title=None, author=None, copyright=None, ccli=None, practice_yn=None, ):
and
def delete_song(self, song_id: int):
and
def add_song_tag(self, song_id: int, song_tag_id: int):
and
def remove_song_tag(self, song_id: int, song_tag_id: int):
REST Login saves user session and is available using username and password too - the function is likely used in tests only.
It's worth checking if it can be removed
Using SongbeamerQS uploading all files takes very long.
looking at the log files each song attachment seems to be downloaded before overwritten.
2023-02-12 17:32:45,080 root DEBUG deleting old file before download
2023-02-12 17:32:45,172 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /api/files/song_arrangement/81 HTTP/1.1" 200 None
2023-02-12 17:32:45,263 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /?q=public/filedownload&id=216&filename=4374385c0f50be8728fbf784a958acfa.txt HTTP/1.1" 200 None
2023-02-12 17:32:45,350 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /?q=public/filedownload&id=222&filename=8188ac2327985931c00262a991462c32.pdf HTTP/1.1" 200 33158
2023-02-12 17:32:45,465 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "DELETE /api/files/song_arrangement/81 HTTP/1.1" 204 0
2023-02-12 17:32:45,580 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "POST /api/files/song_arrangement/81 HTTP/1.1" 200 None
2023-02-12 17:32:45,581 root DEBUG Upload successful {'data': [{'id': 7783, 'domainType': 'song_arrangement', 'domainId': '81', 'name': 'Jesus Erlöser der Welt - D.pdf', 'filename': 'b4120713e6096f5473303bec276e828d947fecfd54fc8d485bbf69eff96d7151', 'fileUrl': 'https://elkw1610.krz.tools/?q=public/filedownload&id=7783&filename=b4120713e6096f5473303bec276e828d947fecfd54fc8d485bbf69eff96d7151', 'imageUrl': None, 'relativeUrl': '?q=public/filedownload&id=7783&filename=b4120713e6096f5473303bec276e828d947fecfd54fc8d485bbf69eff96d7151', 'showOnlyWhenEditable': False, 'securityLevelId': None, 'type': 'file', 'size': 33158, 'additionalInfos': [], 'meta': {'createdDate': '2023-02-12T16:32:45Z', 'createdPerson': None, 'modifiedDate': '2023-02-12T16:32:45Z', 'modifiedPerson': None}}], 'meta': {'count': 1}}
This might be required because of an overwrite option - check that it's implemented the most efficient way when overwrite=True
shouldn't ChurchToolsApi be inside init.py of ChurchToolsApi instead of it's own file?
e.g.
file_upload(self, source_filepath, domain_type, domain_identifier,
custom_file_name=None,
with optional personId keyword
see e3b025b
there might be a / too much with the secure folder - if working the two new lines it .gitignore should not be required
e.g. eventId and song_id
@kolibri52 issues with missing CSRF token...
with optional ID keyword
There is a codeblock in def file_upload(self, source_filepath, domain_type, domain_identifier, custom_file_name=None, overwrite=False):
"""
# Issues with HEADERS in Request module when using non standard 'files[]' key in POST Request
# Workaround for ChurchTools - generate session with /api/whoami GET request and reuse it
# Requests module usually automatically completes required header Params e.g. Content-Type ...
# in case manual header e.g. for AUTH is used, headers don't auto complete
# and server rejects messsages or data is ommited
# Error Code 500 is also missing in API documentation
headers = {'Authorization': 'Login GEHEIM'}
response_test = requests.post(url=url, headers=headers, files=files)
#> this fails !
"""
This might be related to previous CSRF Token issues - can this be removed?
Traceback (most recent call last): File "/home/benste/PycharmProjects/SongBeamerQS/main.py", line 489, in <module> upload_local_songs_by_id(df_sng, df_ct) File "/home/benste/PycharmProjects/SongBeamerQS/main.py", line 453, in upload_local_songs_by_id api.file_upload("/".join([row['path'], row['filename']]), domain_type='song_arrangement', File "/home/benste/PycharmProjects/ChurchToolsAPI/ChurchToolsApi.py", line 299, in file_upload self.file_delete(domain_type, domain_identifier, delete_file_name) File "/home/benste/PycharmProjects/ChurchToolsAPI/ChurchToolsApi.py", line 350, in file_delete files = json.loads(response.content)['data'] KeyError: 'data'
Logging shows
2023-02-12 20:44:05,661 root DEBUG deleting old file before download 2023-02-12 20:44:05,730 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /api/files/song_arrangement/998 HTTP/1.1" 200 None 2023-02-12 20:44:05,826 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "DELETE /api/files/6989 HTTP/1.1" 204 0 2023-02-12 20:44:05,868 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "POST /api/files/song_arrangement/998 HTTP/1.1" 429 None 2023-02-12 20:44:05,869 root WARNING {"message":"Too many requests","translatedMessage":"","messageKey":"","args":[],"errors":[]} 2023-02-12 20:44:05,870 root DEBUG deleting old file before download 2023-02-12 20:44:05,909 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "GET /api/files/song_arrangement/1001 HTTP/1.1" 429 None
since there is an endpoint for the export of the agenda within the API (see https://elkw1610.krz.tools/api/) it should be implemented.
I would suggest to define it as followed:
export_event_agenda(target_format, agenda_id, target_path)
/home/benste/PycharmProjects/SongBeamerQS/venv/bin/python /home/benste/PycharmProjects/SongBeamerQS/main.py
Traceback (most recent call last):
File "/home/benste/PycharmProjects/SongBeamerQS/main.py", line 421, in <module>
upload_new_local_songs_and_generate_ct_id(df_sng, df_ct)
File "/home/benste/PycharmProjects/SongBeamerQS/main.py", line 353, in upload_new_local_songs_and_generate_ct_id
song_id = api.create_song(title=title, songcategory_id=category_id, author=authors,
File "/home/benste/PycharmProjects/ChurchToolsAPI/ChurchToolsApi.py", line 395, in create_song
new_id = int(json.loads(response.content)['data'])
KeyError: 'data'
Process finished with exit code 1
Creating a new song without ID and running the SongBeamerQS script results in an error which is likely caused by the return value of create_song() in CT API
Module logging does shows 403 ... maybe auth related?
2023-01-19 16:52:05,761 root INFO Uploading Song '910 Psalm 86' with Category ID '9' from '' with (C) from '' and ccli ''
2023-01-19 16:52:05,834 urllib3.connectionpool DEBUG https://elkw1610.krz.tools:443 "POST /?q=churchservice/ajax&func=addNewSong HTTP/1.1" 403 None
e.g. get_events() shows quicktip return type "any"
Match with other functions ...
Consider providing legacy access to old kwarg but raising a warning...
after fixing #42 try to build a simple docker image which can run the web-ui
Add files that are required to release this project as a pip installable package.
from setuptools import setup, find_packages
setup(
name='your_package_name',
version='0.1',
author='Your Name',
author_email='[email protected]',
description='A short description of your package',
packages=find_packages(),
install_requires=[
'dependency1',
'dependency2',
# Add more dependencies as necessary
],
)
Document use of
install_requires=[
'other_dependency',
'your_package_name @ git+https://github.com/username/repository.git@tag#egg=your_package_name'
]
Using the WebService the list of events is stating 8:00 and 8:15 instead of 10:00
test fails with current dev_benste branch
Error
Traceback (most recent call last):
File "/home/benste/PycharmProjects/ChurchToolsAPI/TestsChurchToolsApi.py", line 254, in test_get_songs_with_tag
self.assertEqual(408, result[0]['id'])
IndexError: list index out of range
Code can be optimized in get_songs_with_tag() to request songs from CT fewer times ...
Implement a function to get and set the number of occurances for a specific service on a specific event id
Using automated tests full day events are compared with a wrong date because e.g. 0:00 ist 22:00 of the previous day.
astimezone() seems to use UTC on gitlab runner - hard coding the timezone value might work but CET/CEST also might affect this workaround
Implemented in https://forum.songbeamer.de/viewtopic.php?f=1&p=23001&sid=d7f00735d9dccdcc0eb7ba89baa0e489#p23001
by kolibri52
needs merge once code is shared
At present the export method only requires agenda_id, because of missing endpoints the filename can not be auto created using the event name and date.
One way would be to make agenda_id an kwarg and allow for another keyword event_id which retrieves the information from the event itself before retrieving the agenda_id.
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-wnsgar97/churchtoolsapi_d9bee8eba01642e9887440cfedb664b7/setup.py", line 7, in <module>
with open('docker/requirements.txt') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'docker/requirements.txt'
[end of output]
will download any of the available files in the song_arrangement even if the file name does not exist.
reproduceable with test_file_download() when upload fails
Followup from #10
Aus https://forum.songbeamer.de/viewtopic.php?f=1&p=23001&sid=d7f00735d9dccdcc0eb7ba89baa0e489#p23001
Implementierung von kolibri52 aber noch nicht geteilt.
Before using packages the secure folder within the project was used to directly inject defaults like domain and token directly within the modules.
Using packages the secure folder does not and should not be imported into the release packages.
Therefore executing main.py or main_web.py needs to provide/ access these details.
Documentation and init methods need to be checked in order to ensure that other users can safely use the package
Need to replace a person as event admin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.