Update to use f-strings with flynt
MODIFY
plextraktsync/config.py
plextraktsync/config.py
@@ -235,6 +235,6 @@ def save(self):
txt.write("# This is .env file for PlexTraktSync\n")
for key in self.env_keys:
if key in self and self[key] is not None:
- txt.write("{}={}\n".format(key, self[key]))
+ txt.write(f"{key}={self[key]}\n")
else:
- txt.write("{}=\n".format(key))
+ txt.write(f"{key}=\n")

MODIFY
plextraktsync/plex_api.py
plextraktsync/plex_api.py
@@ -193,7 +193,7 @@ def duration(self):
hours, remainder = divmod(self.item.duration / 1000, 3600)
minutes, seconds = divmod(remainder, 60)
- return '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
+ return f'{int(hours):02}:{int(minutes):02}:{int(seconds):02}'
@cached_property
def has_media(self):
@@ -289,9 +289,9 @@ def audio_channels(self):
return None
if channels < 3:
- return "%.01f" % channels
+ return f"{channels:.01f}"
- return "%.01f" % (channels - 0.9)
+ return f"{channels - 0.9:.01f}"
@property
def audio_codec(self):

MODIFY
plextraktsync/plex_server.py
plextraktsync/plex_server.py
@@ -95,4 +95,4 @@ def save_new_url(self, base_url: str, local_url: str):
config["PLEX_BASEURL"] = base_url
config["PLEX_LOCALURL"] = local_url
config.save()
- self.logger.info("Plex server url changed to {}".format(base_url))
+ self.logger.info(f"Plex server url changed to {base_url}")

MODIFY
plextraktsync/trakt_api.py
plextraktsync/trakt_api.py
@@ -123,7 +123,7 @@ def me(self):
try:
return trakt.users.User("me")
except (OAuthException, ForbiddenException) as e:
- logger.fatal("Trakt authentication error: {}".format(str(e)))
+ logger.fatal(f"Trakt authentication error: {str(e)}")
raise e
@cached_property

MODIFY
plextraktsync/trakt_list_util.py
plextraktsync/trakt_list_util.py
class LazyUserList(UserList):
@get
def get_items(self):
- data = yield "users/{user}/lists/{id}/items".format(
- user=slugify(self.creator), id=self.slug
- )
+ data = yield f"users/{slugify(self.creator)}/lists/{self.slug}/items"
for item in data:
if "type" not in item:
continue
@@ -28,9 +26,7 @@ def get_items(self):
@classmethod
@get
def _get(cls, title, creator):
- data = yield "users/{user}/lists/{id}".format(
- user=slugify(creator), id=slugify(title)
- )
+ data = yield f"users/{slugify(creator)}/lists/{slugify(title)}"
extract_ids(data)
ulist = LazyUserList(creator=creator, **data)
ulist.get_items()
@@ -82,14 +78,14 @@ def __init__(self):
def addList(self, username, listname, trakt_list=None):
if trakt_list is not None:
self.lists.append(TraktList.from_trakt_list(listname, trakt_list))
- logger.info("Downloaded List {}".format(listname))
+ logger.info(f"Downloaded List {listname}")
return
try:
self.lists.append(TraktList(username, listname))
- logger.info("Downloaded List {}".format(listname))
+ logger.info(f"Downloaded List {listname}")
except (NotFoundException, OAuthException):
logger.warning(
- "Failed to get list {} by user {}".format(listname, username)
+ f"Failed to get list {listname} by user {username}"
)
def addPlexItemToLists(self, m):

Update to use f-strings with flynt