minor code cleanup

pull/162/head
salty 3 years ago
parent f8fa315c6a
commit 72b195009c
No known key found for this signature in database
GPG Key ID: 5B59BEBA76C5A7FD

@ -177,9 +177,11 @@ class PVR(ABC):
if 'json' in req.headers['Content-Type'].lower():
response_json = misc.get_response_dict(req.json(), identifier_field, identifier)
if (req.status_code == 201 or req.status_code == 200) \
and (response_json and identifier_field in response_json) \
and response_json[identifier_field] == identifier:
if (
req.status_code in [201, 200]
and (response_json and identifier_field in response_json)
and response_json[identifier_field] == identifier
):
log.debug("Successfully added: \'%s [%d]\'", payload['title'], identifier)
return True
elif response_json and ('errorMessage' in response_json or 'message' in response_json):

@ -66,8 +66,7 @@ class Trakt:
req, resp_data = self._make_request(url, payload)
if req.status_code == 200 and len(resp_data):
resp_json = json.loads(resp_data)
return resp_json
return json.loads(resp_data)
elif req.status_code == 401:
log.error("The authentication to Trakt is revoked. Please re-authenticate.")
exit()
@ -133,9 +132,9 @@ class Trakt:
try:
resp_data = ''
max_attempts = 6
while True:
attempts = 0
max_attempts = 6
retrieve_error = False
while attempts <= max_attempts:
try:

@ -147,13 +147,12 @@ class Config(object, metaclass=Singleton):
return self.log_path
def build_config(self):
if not os.path.exists(self.config_path):
if os.path.exists(self.config_path):
return False
print("Dumping default config to: %s" % self.config_path)
with open(self.config_path, 'w') as fp:
json.dump(self.base_config, fp, sort_keys=True, indent=2)
return True
else:
return False
def dump_config(self):
if os.path.exists(self.config_path):
@ -184,10 +183,10 @@ class Config(object, metaclass=Singleton):
continue
# iterate children
if isinstance(v, dict) or isinstance(v, list):
if isinstance(v, (dict, list)):
merged[k], did_upgrade = self.__inner_upgrade(settings1[k], settings2[k], key=k,
overwrite=overwrite)
sub_upgraded = did_upgrade if did_upgrade else sub_upgraded
sub_upgraded = did_upgrade or sub_upgraded
elif settings1[k] != settings2[k] and overwrite:
merged = settings1
sub_upgraded = True

@ -28,7 +28,7 @@ class Pushover:
'priority': self.priority,
}
resp = requests.post('https://api.pushover.net/1/messages.json', data=payload, timeout=30)
return True if resp.status_code == 200 else False
return resp.status_code == 200
except Exception:
log.exception("Error sending notification to %r", self.user_token)

@ -31,7 +31,7 @@ class Slack:
payload['channel'] = self.channel
resp = requests.post(self.webhook_url, json=payload, timeout=30)
return True if resp.status_code == 200 else False
return resp.status_code == 200
except Exception:
log.exception("Error sending notification to %r", self.webhook_url)

@ -111,7 +111,7 @@ def validate_pvr(pvr, pvr_type, notifications):
def get_quality_profile_id(pvr, quality_profile):
# retrieve profile id for requested quality profile
quality_profile_id = pvr.get_quality_profile_id(quality_profile)
if not quality_profile_id or not quality_profile_id > 0:
if not quality_profile_id or quality_profile_id <= 0:
log.error("Aborting due to failure to retrieve Quality Profile ID for: %s", quality_profile)
exit()
log.info("Retrieved Quality Profile ID for \'%s\': %d", quality_profile, quality_profile_id)
@ -121,7 +121,7 @@ def get_quality_profile_id(pvr, quality_profile):
def get_language_profile_id(pvr, language_profile):
# retrieve profile id for requested language profile
language_profile_id = pvr.get_language_profile_id(language_profile)
if not language_profile_id or not language_profile_id > 0:
if not language_profile_id or language_profile_id <= 0:
log.error("No Language Profile ID for: %s", language_profile)
else:
log.info("Retrieved Language Profile ID for \'%s\': %d", language_profile, language_profile_id)
@ -267,8 +267,7 @@ def show(
tag_names)
else:
log.info("ADDED: \'%s (%s)\'", series_title, series_year)
else:
if profile_tags is not None:
elif profile_tags is not None:
log.error("FAILED ADDING: \'%s (%s)\' with Sonarr Tags: %s", series_title, series_year,
tag_names)
else:
@ -1399,7 +1398,7 @@ def automatic_shows(
)
if added_shows is None:
if not list_type.lower() == 'lists':
if list_type.lower() != 'lists':
log.info("FAILED ADDING shows from Trakt's \'%s\' list.", list_type)
time.sleep(10)
continue
@ -1535,7 +1534,7 @@ def automatic_movies(
)
if added_movies is None:
if not list_type.lower() == 'lists':
if list_type.lower() != 'lists':
log.info("FAILED ADDING movies from Trakt's \'%s\' list.", list_type.capitalize())
time.sleep(10)
continue

Loading…
Cancel
Save