Skip to content

Improve logging for better control over logs #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/instawebhooks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def closure_check_regex(arg_value):
description="Monitor Instagram accounts for new posts and send them to a Discord webhook",
epilog="https://github.com/RaenLua/InstaWebhooks",
)
group = parser.add_mutually_exclusive_group()
parser.add_argument(
"instagram_username",
help="the Instagram username to monitor for new posts",
Expand All @@ -70,9 +71,8 @@ def closure_check_regex(arg_value):
r"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_.-]*)$"
),
)
parser.add_argument(
"-v", "--verbose", help="increase output verbosity", action="store_true"
)
group.add_argument("-q", "--quiet", help="hide all logging", action="store_true")
group.add_argument("-v", "--verbose", help="show debug logging", action="store_true")
parser.add_argument(
"-i",
"--refresh-interval",
Expand All @@ -97,9 +97,14 @@ def closure_check_regex(arg_value):
args = parser.parse_args()

# Set the logger to debug if verbose is enabled
if args.verbose:
if args.quiet:
logger.setLevel(logging.CRITICAL)
logger.debug("Quiet output enabled.")
elif args.verbose:
logger.setLevel(logging.DEBUG)
logger.debug("Verbose output enabled.")
else:
logger.setLevel(logging.INFO)

# Log the start of the program
logger.info("Starting InstaWebhooks...")
Expand Down Expand Up @@ -200,7 +205,7 @@ async def send_to_discord(post: Post):
if args.message_content:
format_message(post)

logger.debug("Sending post sent to Discord")
logger.debug("Sending post sent to Discord...")

if not args.no_embed:
embed, post_image_file, profile_pic_file = await create_embed(post)
Expand Down Expand Up @@ -233,12 +238,12 @@ async def check_for_new_posts():
lambda p: p.date > until, dropwhile(lambda p: p.date > since, posts)
):
new_posts_found = True
logger.debug("New post found: https://www.instagram.com/p/%s", post.shortcode)
logger.info("New post found: https://www.instagram.com/p/%s", post.shortcode)
await send_to_discord(post)
sleep(2) # Avoid 30 requests per minute rate limit

if not new_posts_found:
logger.debug("No new posts found.")
logger.info("No new posts found.")


def main():
Expand Down