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

More configs for apprise and more #203

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ runbot.bat
/google_trends.dat
/google_trends.dir
/google_trends.bak
/config-private.yaml
/config.yaml
5 changes: 0 additions & 5 deletions .template-config-private.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be restored, not having it increases the chances someone accidentally commits secret information and from personal experience makes it harder to develop as a result.

It's a bit jarring for people to move things back from config-private.yaml to config.yaml again as well.

This file was deleted.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
this [link](https://learn.microsoft.com/en-GB/cpp/windows/latest-supported-vc-redist?view=msvc-170) and reboot your
computer

4. Edit the `accounts.json.sample` with your accounts credentials and rename it by removing `.sample` at the end.
4. Edit the `config.yaml.sample` accordingly and rename it by removing `.sample` at the end.

5. Edit the `accounts.json.sample` with your accounts credentials and rename it by removing `.sample` at the end.

The "totp" field is not mandatory, only enter your TOTP key if you use it for 2FA (if ommitting, don't keep
it as an empty string, remove the line completely).
Expand All @@ -72,11 +74,11 @@
]
```

5. Run the script:
6. Run the script:

`python main.py`

6. (Windows Only) You can set up automatic execution by generating a Task Scheduler XML file.
7. (Windows Only) You can set up automatic execution by generating a Task Scheduler XML file.

If you are a Windows user, run the `generate_task_xml.py` script to create a `.xml` file. After generating the file, import it into Task Scheduler to schedule automatic execution of the script. This will allow the script to run at the specified time without manual intervention.

Expand Down
7 changes: 0 additions & 7 deletions config.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions config.yaml.sample
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this .sample just complicates things needlessly. We should just have the file with defaults. Just isn't a common practice with config (with exception of private files usually).

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# RENAME THIS FILE TO config.yaml ONCE CONFIGURED
apprise:
summary: ON_ERROR
exceptions: True # True or False (Whether to send or not exceptions)
promotions: True # True or False (Whether to send or not incomplete promotions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be a bit clearer, it'd be nice to change this to apprise.notify.uncaught-exceptions and apprise.notify.incomplete-promotions. Reads a bit better/is clearer IMO.

urls:
- 'discord://{WebhookID}/{WebhookToken}' # Replace with your actual Apprise service URLs
retries:
base_delay_in_seconds: 14.0625 # base_delay_in_seconds * 2^max = 14.0625 * 2^6 = 900 = 15 minutes
max: 8
strategy: EXPONENTIAL
default_geolocation: US # Replace with your country code https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
logging: DEBUG # DEBUG or INFO
27 changes: 19 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def main():
earned_points = executeBot(currentAccount, args)
except Exception as e1:
logging.error("", exc_info=True)
Utils.sendNotification(
f"⚠️ Error executing {currentAccount.username}, please check the log",
traceback.format_exc(),
)
if Utils.loadConfig().get("apprise", {}).get("exceptions", True):
Utils.sendNotification(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify things, we could add an optional exception parameter (defaults to None). If an exception is provided in sendNotification, we can check the config to see if sending is enabled. If it is, we send. If it isn't, we just return.

f"⚠️ Error executing {currentAccount.username}, please check the log",
traceback.format_exc(),
)
continue
previous_points = previous_points_data.get(currentAccount.username, 0)

Expand Down Expand Up @@ -99,14 +100,23 @@ def setupLogging():

# so only our code is logged if level=logging.DEBUG or finer
# if not working see https://stackoverflow.com/a/48891485/4164390
_levels = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL': logging.CRITICAL
}
log_level_str = Utils.loadConfig().get("logging", "DEBUG").upper()
log_level = _levels.get(log_level_str, logging.DEBUG)
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": True,
}
)
logging.basicConfig(
level=logging.DEBUG,
level=log_level,
format=_format,
handlers=[
handlers.TimedRotatingFileHandler(
Expand Down Expand Up @@ -356,6 +366,7 @@ def save_previous_points_data(data):
main()
except Exception as e:
logging.exception("")
Utils.sendNotification(
"⚠️ Error occurred, please check the log", traceback.format_exc()
)
if Utils.loadConfig().get("apprise", {}).get("exceptions", True):
Utils.sendNotification(
"⚠️ Error occurred, please check the log", traceback.format_exc()
)
6 changes: 4 additions & 2 deletions src/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def browserSetup(
options.add_argument("--disable-default-apps")
options.add_argument("--disable-features=Translate")
options.add_argument("--disable-features=PrivacySandboxSettings4")
options.add_argument("--disable-http2")
options.add_argument("--disable-search-engine-choice-screen") #153

seleniumwireOptions: dict[str, Any] = {"verify_ssl": False}
Expand Down Expand Up @@ -205,8 +206,9 @@ def getCCodeLang(lang: str, geo: str) -> tuple:
try:
nfo = ipapi.location()
except RateLimited:
logging.warning("Returning default", exc_info=True)
return "en", "US"
geo = Utils.loadConfig().get("default_geolocation", "US").upper()
logging.warning(f"Returning default geolocation {geo}", exc_info=True)
return "en", geo
if isinstance(nfo, dict):
if lang is None:
lang = nfo["languages"].split(",")[0].split("-")[0]
Expand Down
4 changes: 2 additions & 2 deletions src/morePromotions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ def completeMorePromotions(self):
for promotion in self.browser.utils.getDashboardData()["morePromotions"]: # Have to refresh
if promotion["pointProgress"] < promotion["pointProgressMax"]:
incompletePromotions.append((promotion["title"], promotion["promotionType"]))
if incompletePromotions:
Utils.sendNotification("Incomplete promotions(s)", incompletePromotions)
if incompletePromotions and Utils.loadConfig().get("apprise", {}).get("promotions", True):
Utils.sendNotification(f"Incomplete promotions(s) for {self.browser.username}", incompletePromotions)
logging.info("[MORE PROMOS] Exiting")
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def sendNotification(title, body) -> None:
if Utils.args.disable_apprise:
return
apprise = Apprise()
urls: list[str] = Utils.loadConfig("config-private.yaml").get("apprise", {}).get("urls", [])
urls: list[str] = Utils.loadConfig().get("apprise", {}).get("urls", [])
if not urls:
logging.debug("No urls found, not sending notification")
return
Expand Down
Loading