Skip to content

Commit

Permalink
name changes and annotation for A001 and A002 #102
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed Oct 8, 2024
1 parent 13420a2 commit 1414b80
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion churchtools_api/churchtools_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions churchtools_api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions churchtools_api/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -109,7 +109,7 @@ def create_song( # noqa: PLR0913
title: str,
songcategory_id: int,
author="",
copyright="",
copyright="", # noqa: A002
ccli="",
tonality="",
bpm="",
Expand Down Expand Up @@ -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
Expand All @@ -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,
):
Expand Down Expand Up @@ -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]
4 changes: 2 additions & 2 deletions main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1414b80

Please sign in to comment.