Giter VIP home page Giter VIP logo

churchtoolsapi's People

Contributors

bensteuem avatar dependabot[bot] avatar fschrempf avatar kolibri52 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

churchtoolsapi's Issues

response of request in get_ct_csrf_token can return 200 with HTML 'not found'

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

Isolate WebUI from ChurchTools API

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

Improve Logging / Tests for logging

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...

Communi API is experiencing issue on loading event

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

Add login status to login_communi in web service

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...

Check response of 2 functions

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):

Optimize Performance of file_upload

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

Check if commented code is obsolete

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?

Error on using file_delete

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

Add function for Agenda export

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)

  • "target_format" supports "SONG_BEAMER", "PRO_PRESENTER_6", "PRO_PRESENTER_7"
  • agenda_id is the ID which can be found within the event data
  • target_path ist the filepath of the retrieved zip package

Fetching song_id on newly updated song fails script

/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

Create a pip installable package

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'
]

test_get_songs_with_tag fails

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 ...

test_get_events runs UTC timezone in git runner

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

Allow use of event_id instead of agenda_id in export_event_agenda ()

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.

Can't install release 1.4. because of invalid setup file

  × 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]

Update documentation for use of secure / defaults like domain

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.