Skip to content
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

Mobile search fix, less CPU usage, & verbose notifs #276

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 12 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@


def main():
setupLogging()
args = argumentParser()
notifier = Notifier(args)
setupLogging(args.verbosenotifs, notifier)
loadedAccounts = setupAccounts()
for currentAccount in loadedAccounts:
try:
Expand All @@ -26,7 +26,10 @@ def main():
logging.exception(f"{e.__class__.__name__}: {e}")


def setupLogging():
def setupLogging(verbose_notifs, notifier):
ColoredFormatter.verbose_notifs = verbose_notifs
ColoredFormatter.notifier = notifier

format = "%(asctime)s [%(levelname)s] %(message)s"
terminalHandler = logging.StreamHandler(sys.stdout)
terminalHandler.setFormatter(ColoredFormatter(format))
Expand Down Expand Up @@ -83,6 +86,12 @@ def argumentParser() -> argparse.Namespace:
default=None,
help="Optional: Discord Webhook URL (ex: https://discord.com/api/webhooks/123456789/ABCdefGhIjKlmNoPQRsTUVwxyZ)",
)
parser.add_argument(
"-vn",
"--verbosenotifs",
action="store_true",
help="Optional: Send all the logs to discord/telegram",
)
return parser.parse_args()


Expand Down Expand Up @@ -151,6 +160,7 @@ def executeBot(currentAccount, notifier: Notifier, args: argparse.Namespace):
accountPointsCounter = Searches(mobileBrowser).bingSearches(
remainingSearchesM
)
desktopBrowser.webdriver.quit()

logging.info(
f"[POINTS] You have earned {desktopBrowser.utils.formatNumber(accountPointsCounter - startingPoints)} points today !"
Expand Down
7 changes: 7 additions & 0 deletions src/loggingColoredFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


class ColoredFormatter(logging.Formatter):
verbose_notifs = False
notifier = str()

grey = "\x1b[38;21m"
blue = "\x1b[38;5;39m"
yellow = "\x1b[38;5;226m"
Expand All @@ -22,5 +25,9 @@ def __init__(self, fmt):

def format(self, record):
logFmt = self.FORMATS.get(record.levelno)

if self.verbose_notifs:
self.notifier.send(f"[{logging.getLevelName(record.levelno)}] {record.msg}")

formatter = logging.Formatter(logFmt)
return formatter.format(record)
14 changes: 13 additions & 1 deletion src/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def bingSearches(self, numberOfSearches: int, pointsCounter: int = 0):

i = 0
search_terms = self.getGoogleTrends(numberOfSearches)
self.webdriver.get("https://bing.com")

for word in search_terms:
i += 1
logging.info("[BING] " + f"{i}/{numberOfSearches}")
Expand All @@ -75,16 +77,26 @@ def bingSearches(self, numberOfSearches: int, pointsCounter: int = 0):
return pointsCounter

def bingSearch(self, word: str):
i = 0

while True:
try:
self.webdriver.get("https://bing.com")
self.browser.utils.waitUntilClickable(By.ID, "sb_form_q")
searchbar = self.webdriver.find_element(By.ID, "sb_form_q")
searchbar.clear()
searchbar.send_keys(word)
searchbar.submit()
time.sleep(random.randint(10, 15))
return self.browser.utils.getBingAccountPoints()
except TimeoutException:
if i == 5:
logging.error(
"[BING] "
+ "Cancelling mobile searches due to too many retries."
)
return self.browser.utils.getBingAccountPoints()

logging.error("[BING] " + "Timeout, retrying in 5 seconds...")
time.sleep(5)
i += 1
continue