From 1414b809373c2273d21871d9ba4c0692b16263bf Mon Sep 17 00:00:00 2001 From: bensteUEM Date: Tue, 8 Oct 2024 20:24:01 +0200 Subject: [PATCH] name changes and annotation for A001 and A002 #102 --- churchtools_api/churchtools_api.py | 2 +- churchtools_api/events.py | 13 ++++++++----- churchtools_api/songs.py | 18 ++++++++++-------- main.ipynb | 4 ++-- pyproject.toml | 1 - 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/churchtools_api/churchtools_api.py b/churchtools_api/churchtools_api.py index 63b3914..b8a73cb 100644 --- a/churchtools_api/churchtools_api.py +++ b/churchtools_api/churchtools_api.py @@ -229,7 +229,7 @@ def get_services(self, **kwargs): logger.info("Services requested failed: %s", response.status_code) return None - def get_tags(self, type="songs"): + def get_tags(self, type="songs"): # noqa: A002 """Retrieve a list of all available tags of a specific ct_domain type from ChurchTools Purpose: be able to find out tag-ids of all available tags for filtering by tag. diff --git a/churchtools_api/events.py b/churchtools_api/events.py index 5ed3fc8..bce46cf 100644 --- a/churchtools_api/events.py +++ b/churchtools_api/events.py @@ -119,9 +119,9 @@ def get_event_by_calendar_appointment( """ if not isinstance(start_date, datetime): formats = {"iso": "%Y-%m-%dT%H:%M:%SZ", "date": "%Y-%m-%d"} - for format in formats: + for date_formats in formats.values(): try: - start_date = datetime.strptime(start_date, format) + start_date = datetime.strptime(start_date, date_formats) break except ValueError: continue @@ -288,10 +288,13 @@ def get_event_admins_ajax(self, eventId: int) -> list: Returns: list of admin ids. """ - event_data = self.get_AllEventData_ajax(eventId) + event_data = self.get_AllEventData_ajax(eventId=eventId) if event_data is not None: if "admin" in event_data: - admin_ids = [int(id) for id in event_data["admin"].split(",")] + admin_ids = [ + int(available_event_id) + for available_event_id in event_data["admin"].split(",") + ] else: admin_ids = [] return admin_ids @@ -314,7 +317,7 @@ def set_event_admins_ajax(self, eventId: int, admin_ids: list) -> bool: data = { "id": eventId, - "admin": ", ".join([str(id) for id in admin_ids]), + "admin": ", ".join([str(admin_id) for admin_id in admin_ids]), "func": "updateEventInfo", } response = self.session.post(url=url, headers=headers, params=params, data=data) diff --git a/churchtools_api/songs.py b/churchtools_api/songs.py index cfe4633..c129852 100644 --- a/churchtools_api/songs.py +++ b/churchtools_api/songs.py @@ -46,9 +46,9 @@ def get_songs(self, **kwargs) -> list[dict]: if "song_id" in kwargs: logger.info( "Did not find song (%s) with CODE %s", - kwargs["song_id"], - response.status_code, - ) + kwargs["song_id"], + response.status_code, + ) return None logger.warning( "%s Something went wrong fetching songs: %s", @@ -109,7 +109,7 @@ def create_song( # noqa: PLR0913 title: str, songcategory_id: int, author="", - copyright="", + copyright="", # noqa: A002 ccli="", tonality="", bpm="", @@ -150,10 +150,10 @@ def create_song( # noqa: PLR0913 if response.status_code == 200: response_content = json.loads(response.content) new_id = int(response_content["data"]) - logger.debug("Song created successful with ID=%s",new_id) + logger.debug("Song created successful with ID=%s", new_id) return new_id - logger.info("Creating song failed with %s",response.status_code) + logger.info("Creating song failed with %s", response.status_code) return None def edit_song( # noqa: PLR0913 @@ -162,7 +162,7 @@ def edit_song( # noqa: PLR0913 songcategory_id=None, title=None, author=None, - copyright=None, + copyright=None, # noqa: A002 ccli=None, practice_yn=None, ): @@ -297,7 +297,9 @@ def get_songs_by_tag(self, song_tag_id) -> list[dict]: songs_dict = {song["id"]: song for song in songs} filtered_song_ids = [ - id for id in songs_dict if self.contains_song_tag(id, song_tag_id) + song_id + for song_id in songs_dict + if self.contains_song_tag(song_id=song_id, song_tag_id=song_tag_id) ] return [songs_dict[song_id] for song_id in filtered_song_ids] diff --git a/main.ipynb b/main.ipynb index 1bb341d..ca1aad4 100644 --- a/main.ipynb +++ b/main.ipynb @@ -73,8 +73,8 @@ "outputs": [], "source": [ "all_song_ids = [value[\"id\"] for value in songs]\n", - "for id in all_song_ids:\n", - " api.add_song_tag(id, 51)" + "for song_id in all_song_ids:\n", + " api.add_song_tag(song_id=song_id, song_tag_id=51)" ] } ], diff --git a/pyproject.toml b/pyproject.toml index 17553be..9f05e69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,6 @@ ignore = [ "PTH110","PTH107","PTH123","PTH118","PTH112","PTH103", #Path changes "SIM115", #context manager for files - "A001","A002", "TRY300", "COM812", "ISC001", #disabled for formatter compatibility