Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions src/instawebhooks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
try:
from aiohttp import ClientSession
from discord import Embed, File, SyncWebhook
from instaloader.exceptions import LoginRequiredException
from instaloader.exceptions import LoginException, LoginRequiredException
from instaloader.instaloader import Instaloader
from instaloader.structures import Post, Profile
except ModuleNotFoundError as exc:
Expand Down Expand Up @@ -45,6 +45,22 @@
else:
logger.setLevel(logging.INFO)

if args.login or args.interactive_login:
logger.info("Logging into Instagram...")
try:
if args.login:
Instaloader().login(*args.login)
if args.interactive_login:
Instaloader().interactive_login(args.interactive_login)
except LoginException as login_exc:
logger.critical("instaloader: error: %s", login_exc)
raise SystemExit(
"An error happened during login. Check if the provided username exists."
) from login_exc
except KeyboardInterrupt:
print("\nLogin interrupted by user.")
sys.exit(0)

# Log the start of the program
logger.info("Starting InstaWebhooks...")

Expand Down Expand Up @@ -207,7 +223,7 @@ def main():
except LoginRequiredException as login_exc:
logger.critical("instaloader: error: %s", login_exc)
raise SystemExit(
"Not logged into Instaloader.\n instaloader --login YOUR-USERNAME"
"Not logged in. Please login with the --login flag."
) from login_exc
except KeyboardInterrupt:
print("\nInterrupted by user.")
Expand Down
27 changes: 24 additions & 3 deletions src/instawebhooks/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def closure_check_regex(arg_value: str):
),
epilog="https://github.com/RaenLua/InstaWebhooks",
)
group = parser.add_mutually_exclusive_group()
logging_group = parser.add_mutually_exclusive_group()
login_group = parser.add_mutually_exclusive_group()
parser.add_argument(
"instagram_username",
help="the Instagram username to monitor for new posts",
Expand All @@ -42,12 +43,32 @@ def closure_check_regex(arg_value: str):
r"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_.-]*)$"
),
)
group.add_argument("-q", "--quiet", help="hide all logging", action="store_true")
group.add_argument("-v", "--verbose", help="show debug logging", action="store_true")
logging_group.add_argument(
"-q", "--quiet", help="hide all logging", action="store_true"
)
logging_group.add_argument(
"-v", "--verbose", help="show debug logging", action="store_true"
)
login_group.add_argument(
"-l",
"--login",
metavar=("USERNAME", "PASSWORD"),
type=str,
help="login to instagram with username and password",
nargs=2,
)
login_group.add_argument(
"-t",
"--interactive-login",
metavar="USERNAME",
type=str,
help="login to instagram with username and ask for password on terminal",
)
parser.add_argument(
"-p",
"--catchup",
help="send the last latest posts on startup regardless of time",
metavar="POSTS",
type=int,
default=0,
)
Expand Down
Loading