From 37f8843f5fecc9bb4a5eb5b18eea35b1bbc16489 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Fri, 5 Jul 2024 22:55:03 +0200 Subject: Add more fixes and linting --- beinc_pull.py | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'beinc_pull.py') diff --git a/beinc_pull.py b/beinc_pull.py index 118a08a..6ce9c2f 100755 --- a/beinc_pull.py +++ b/beinc_pull.py @@ -1,8 +1,7 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# Blackmore's Enhanced IRC-Notification Collection (BEINC) v4.3 -# Copyright (C) 2013-2022 Simeon Simeonov +# Blackmore's Enhanced IRC-Notification Collection (BEINC) +# Copyright (C) 2013-2024 Simeon Simeonov # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,14 +16,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . """A simple client that pulls notifications from a BEINC server""" + import argparse import errno import getpass import io import json import os +import pathlib import sched -import socket import ssl import sys import time @@ -38,7 +38,7 @@ except ImportError: __author__ = 'Simeon Simeonov' -__version__ = '4.3' +__version__ = '4.4' __license__ = 'GPL3' @@ -63,14 +63,14 @@ def fetch_password(args_password): except KeyboardInterrupt: eprint(os.linesep + 'Prompt terminated') sys.exit(errno.EACCES) - elif os.path.isfile(args_password): + elif pathlib.Path(args_password).is_file(): try: with io.open(args_password, 'r', encoding='utf-8') as fp: passwd = fp.readline() if passwd.strip(): return passwd.strip() - except Exception as e: - eprint(f'Unable to open password file: {e}') + except Exception as exp: + eprint(f'Unable to open password file: {exp}') sys.exit(1) return args_password @@ -98,8 +98,7 @@ def display_notification(args, title, message): if not pynotify.init('BEINC Notify'): raise Exception('There was a problem with libnotify') notification_obj = pynotify.Notification( - summary=title, - message=message, + summary=title, message=message ) notification_obj.timeout = 1000 * args.osd_timeout notification_obj.set_category('im.received') @@ -139,25 +138,23 @@ def pull_notifications(scheduler, args): ) response_dict = json.loads(response.read().decode('utf-8')) if response.code != 200: - raise socket.error(response_dict.get('message', '')) + raise OSError(response_dict.get('message', '')) for entry in response_dict['data']['messages']: display_notification( - args, - entry.get('title', ''), - entry.get('message', ''), + args, entry.get('title', ''), entry.get('message', '') ) response.close() scheduler.enter( args.frequency, 1, pull_notifications, (scheduler, args) ) - except ssl.SSLError as e: - eprint(f'BEINC SSL/TLS error: {e}') + except ssl.SSLError as err: + eprint(f'BEINC SSL/TLS error: {err}') sys.exit(errno.EPERM) - except socket.error as e: - eprint(f'BEINC connection error: {e}') + except OSError as err: + eprint(f'BEINC connection error: {err}') sys.exit(errno.EPERM) - except Exception as e: - eprint(f'BEINC generic client error: {e}') + except Exception as exp: + eprint(f'BEINC generic client error: {exp}') sys.exit(errno.EPERM) @@ -167,10 +164,7 @@ def main(inargs=None): description='The following options are available' ) parser.add_argument( - 'url', - metavar='URL', - type=str, - help='BEINC server destination URL', + 'url', metavar='URL', type=str, help='BEINC server destination URL' ) parser.add_argument( '-c', -- cgit v1.3