Skip to content

Commit 26983d6

Browse files
authored
Merge pull request #12 from RyanLua/improved-logging
Improve logging for better control over logs
2 parents 543d0bb + e7a6b7f commit 26983d6

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/instawebhooks/__main__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def closure_check_regex(arg_value):
5858
description="Monitor Instagram accounts for new posts and send them to a Discord webhook",
5959
epilog="https://github.com/RaenLua/InstaWebhooks",
6060
)
61+
group = parser.add_mutually_exclusive_group()
6162
parser.add_argument(
6263
"instagram_username",
6364
help="the Instagram username to monitor for new posts",
@@ -70,9 +71,8 @@ def closure_check_regex(arg_value):
7071
r"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_.-]*)$"
7172
),
7273
)
73-
parser.add_argument(
74-
"-v", "--verbose", help="increase output verbosity", action="store_true"
75-
)
74+
group.add_argument("-q", "--quiet", help="hide all logging", action="store_true")
75+
group.add_argument("-v", "--verbose", help="show debug logging", action="store_true")
7676
parser.add_argument(
7777
"-i",
7878
"--refresh-interval",
@@ -97,9 +97,14 @@ def closure_check_regex(arg_value):
9797
args = parser.parse_args()
9898

9999
# Set the logger to debug if verbose is enabled
100-
if args.verbose:
100+
if args.quiet:
101+
logger.setLevel(logging.CRITICAL)
102+
logger.debug("Quiet output enabled.")
103+
elif args.verbose:
101104
logger.setLevel(logging.DEBUG)
102105
logger.debug("Verbose output enabled.")
106+
else:
107+
logger.setLevel(logging.INFO)
103108

104109
# Log the start of the program
105110
logger.info("Starting InstaWebhooks...")
@@ -188,7 +193,7 @@ async def send_to_discord(post: Post):
188193
if args.message_content:
189194
format_message(post)
190195

191-
logger.debug("Sending post sent to Discord")
196+
logger.debug("Sending post sent to Discord...")
192197

193198
if not args.no_embed:
194199
embed, post_image_file, profile_pic_file = await create_embed(post)
@@ -221,12 +226,12 @@ async def check_for_new_posts():
221226
lambda p: p.date > until, dropwhile(lambda p: p.date > since, posts)
222227
):
223228
new_posts_found = True
224-
logger.debug("New post found: https://www.instagram.com/p/%s", post.shortcode)
229+
logger.info("New post found: https://www.instagram.com/p/%s", post.shortcode)
225230
await send_to_discord(post)
226231
sleep(2) # Avoid 30 requests per minute rate limit
227232

228233
if not new_posts_found:
229-
logger.debug("No new posts found.")
234+
logger.info("No new posts found.")
230235

231236

232237
def main():

0 commit comments

Comments
 (0)