Skip to content

Commit

Permalink
Merge pull request #583 from Hari-Nagarajan/development
Browse files Browse the repository at this point in the history
0.6.1
  • Loading branch information
DakkJaniels committed Mar 19, 2021
2 parents 5bd547c + 83bd7a6 commit bb7713f
Show file tree
Hide file tree
Showing 14 changed files with 713 additions and 986 deletions.
5 changes: 3 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pyinstaller = "*"
requests = "==2.24.0"
click = "*"
selenium = "*"
chromedriver-py = "==89.0.4389.23"
chromedriver-py = "==88.0.4324.96"
furl = "*"
twilio = "*"
discord-webhook = "*"
Expand All @@ -23,7 +23,7 @@ prompt_toolkit = "*"
aiohttp = "*"
pyobjc = { version = "*", sys_platform = "== 'darwin'" }
async-timeout = "*"
amazoncaptcha = "==0.4.4"
amazoncaptcha = "*"
browser-cookie3 = "*"
coloredlogs = "*"
apprise = "*"
Expand All @@ -35,6 +35,7 @@ stdiomask = "*"
packaging = "*"
config = "*"
lxml = "*"
dnspython = "*"

[requires]
python_version = "3.8"
1 change: 0 additions & 1 deletion _bbuy-fe.bat

This file was deleted.

1 change: 0 additions & 1 deletion _bbuy-gbyte.bat

This file was deleted.

1 change: 0 additions & 1 deletion _bbuy-msi.bat

This file was deleted.

3 changes: 0 additions & 3 deletions _nvidiadotcom.bat

This file was deleted.

19 changes: 17 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@ def sha256sum(filename):
exit(0)


from cli import cli
def notfound_message(exception):
print(exception)
print(
f"Missing '{exception.name}' module. If you ran 'pipenv install', try 'pipenv install {exception.name}'"
)
print("Exiting...")


try:
from cli import cli
except ModuleNotFoundError as e:
notfound_message(e)
exit(0)

if __name__ == "__main__":
cli.main()
try:
cli.main()
except ModuleNotFoundError as e:
notfound_message(e)
exit(0)
150 changes: 115 additions & 35 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,26 @@
# https://github.com/Hari-Nagarajan/fairgame

import os
import platform
import shutil
import time
from datetime import datetime
from functools import wraps
from pathlib import Path
from signal import signal, SIGINT

LICENSE_PATH = os.path.join(
"cli",
"license",
)


try:
import click
except ModuleNotFoundError as e:
print(e)
print("Install the missing module noted above.")
exit(0)
import time
from signal import SIGINT, signal

import click

from common.globalconfig import AMAZON_CREDENTIAL_FILE, GlobalConfig
from notifications.notifications import NotificationHandler, TIME_FORMAT
from stores.amazon import Amazon
from utils.logger import log
from common.globalconfig import GlobalConfig, AMAZON_CREDENTIAL_FILE
from utils.version import is_latest, version
from stores.amazon import Amazon
from stores.bestbuy import BestBuyHandler

LICENSE_PATH = os.path.join(
"cli",
"license",
)


def get_folder_size(folder):
Expand All @@ -59,8 +52,9 @@ def sizeof_fmt(num, suffix="B"):
return "%.1f%s%s" % (num, "Yi", suffix)


def handler(signal, frame):
log.info("Caught the stop, exiting.")
# see https://docs.python.org/3/library/signal.html
def interrupt_handler(signal_num, frame):
log.info(f"Caught the interrupt signal. Exiting.")
exit(0)


Expand All @@ -71,7 +65,7 @@ def decorator(*args, **kwargs):
func(*args, **kwargs)
except KeyboardInterrupt:
pass
except:
else:
notification_handler.send_notification(f"FairGame has crashed.")
raise

Expand All @@ -80,7 +74,6 @@ def decorator(*args, **kwargs):

@click.group()
def main():

pass


Expand Down Expand Up @@ -196,6 +189,12 @@ def main():
default=False,
help="Directly hit the offers page. Preferred, but deprecated by Amazon.",
)
@click.option(
"--captcha-wait",
is_flag=True,
default=False,
help="Wait if captcha could not be solved. Only occurs if enters captcha handler during checkout.",
)
@notify_on_crash
def amazon(
no_image,
Expand All @@ -216,6 +215,7 @@ def amazon(
clean_profile,
clean_credentials,
alt_offers,
captcha_wait,
):
notification_handler.sound_enabled = not disable_sound
if not notification_handler.sound_enabled:
Expand Down Expand Up @@ -248,6 +248,7 @@ def amazon(
log_stock_check=log_stock_check,
shipping_bypass=shipping_bypass,
alt_offers=alt_offers,
wait_on_captcha_fail=captcha_wait,
)
try:
amzn_obj.run(delay=delay, test=test)
Expand All @@ -257,17 +258,6 @@ def amazon(
time.sleep(5)


@click.command()
@click.option("--sku", type=str, required=True)
@click.option("--headless", is_flag=True)
@notify_on_crash
def bestbuy(sku, headless):
bb = BestBuyHandler(
sku, notification_handler=notification_handler, headless=headless
)
bb.run_item()


@click.option(
"--disable-sound",
is_flag=True,
Expand Down Expand Up @@ -302,6 +292,7 @@ def test_notifications(disable_sound):
@click.option("--w", is_flag=True)
@click.option("--c", is_flag=True)
def show(w, c):
show_file = "show_c.txt"
if w and c:
print("Choose one option. Program Quitting")
exit(0)
Expand All @@ -328,12 +319,101 @@ def show(w, c):
exit(0)


signal(SIGINT, handler)
@click.command()
@click.option(
"--domain",
help="Specify the domain you want to find endpoints for (e.g. www.amazon.de, www.amazon.com, smile.amazon.com.",
)
def find_endpoints(domain):
import dns.resolver

if not domain:
log.error("You must specify a domain to resolve for endpoints with --domain.")
exit(0)
log.info(f"Attempting to resolve '{domain}'")
# Default
my_resolver = dns.resolver.Resolver()
try:
resolved = my_resolver.resolve(domain)
for rdata in resolved:
log.info(f"Your computer resolves {domain} to {rdata.address}")
except Exception as e:
log.error(f"Failed to use local resolver due to: {e}")
exit(1)

# Find endpoints from various DNS servers
endpoints, resolutions = resolve_domain(domain)
log.info(
f"{domain} resolves to at least {len(endpoints)} distinct IP addresses across {resolutions} lookups:"
)
endpoints = sorted(endpoints)
for endpoint in endpoints:
log.info(f" {endpoint}")

return endpoints


def resolve_domain(domain):
import dns.resolver

public_dns_servers = global_config.get_fairgame_config().get("public_dns_servers")
resolutions = 0
endpoints = set()

# Resolve the domain for each DNS server to find out how many end points we have
for provider in public_dns_servers:
# Provider is Google, Verisign, etc.
log.info(f"Testing {provider}")
for server in public_dns_servers[provider]:
# Server is 8.8.8.8 or 1.1.1.1
my_resolver = dns.resolver.Resolver()
my_resolver.nameservers = [server]

try:
resolved = my_resolver.resolve(domain)
except Exception as e:
log.warning(
f"Unable to resolve using {provider} server {server} due to: {e}"
)
continue
for rdata in resolved:
ipv4_address = rdata.address
endpoints.add(ipv4_address)
resolutions += 1
log.debug(f"{domain} resolves to {ipv4_address} via {server}")
return endpoints, resolutions


@click.command()
@click.option(
"--domain", help="Specify the domain you want to generate traceroute commands for."
)
def show_traceroutes(domain):
if not domain:
log.error("You must specify a domain to test routes using --domain.")
exit(0)

# Get the endpoints to test
endpoints, resolutions = resolve_domain(domain=domain)

if platform.system() == "Windows":
trace_command = "tracert -d "
else:
trace_command = "traceroute -n "

# Spitball test routes via Python's traceroute
for endpoint in endpoints:
log.info(f" {trace_command}{endpoint}")


# Register Signal Handler for Interrupt
signal(SIGINT, interrupt_handler)

main.add_command(amazon)
main.add_command(bestbuy)
main.add_command(test_notifications)
main.add_command(show)
main.add_command(find_endpoints)
main.add_command(show_traceroutes)

# Global scope stuff here
if is_latest():
Expand Down
8 changes: 8 additions & 0 deletions common/globalconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ def get_amazon_config(self, encryption_pass=None):
)
return amazon_config

def get_fairgame_config(self):
return self.fairgame_config

def get_browser_profile_path(self):
if not self.profile_path:
self.profile_path = os.path.join(
os.path.dirname(os.path.abspath("__file__")),
self.global_config["FAIRGAME"].get("profile_name", ".profile-amz"),
)
return self.profile_path

def get_property(self, property_name):
if property_name not in self.global_config.keys(): # we don't want KeyError
return None # just return None if not found
return self.global_config[property_name]
Loading

0 comments on commit bb7713f

Please sign in to comment.