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
Changes from 1 commit
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
Prev Previous commit
Restored configurarion files
Guido30 committed Sep 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit dcdfdce68966b61689130ea24d6b765585074b84
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -186,4 +186,4 @@ runbot.bat
/google_trends.dat
/google_trends.dir
/google_trends.bak
/config.yaml
/config-private.yaml
5 changes: 5 additions & 0 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# config-private.yaml
apprise:
urls:
- "discord://{WebhookID}/{WebhookToken}" # Replace with your actual Apprise service URLs
default_geolocation: US # Replace with your country code https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably safe to keep this in config.yaml

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
this [link](https://learn.microsoft.com/en-GB/cpp/windows/latest-supported-vc-redist?view=msvc-170) and reboot your
computer

4. Edit the `config.yaml.sample` accordingly and rename it by removing `.sample` at the end.
4. Edit the `.template-config-private.yaml` accordingly and rename it to `config-private.yaml`.

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

11 changes: 11 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# config.yaml
apprise:
summary: ON_ERROR
notify:
uncaught-exceptions: True # True or False
incomplete-promotions: True # True or False
retries:
base_delay_in_seconds: 14.0625 # base_delay_in_seconds * 2^max = 14.0625 * 2^6 = 900 = 15 minutes
max: 8
strategy: EXPONENTIAL
logging: DEBUG # DEBUG or INFO
13 changes: 0 additions & 13 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).

This file was deleted.

17 changes: 8 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -40,11 +40,11 @@ def main():
earned_points = executeBot(currentAccount, args)
except Exception as e1:
logging.error("", exc_info=True)
if Utils.loadConfig().get("apprise", {}).get("exceptions", True):
Utils.sendNotification(
f"⚠️ Error executing {currentAccount.username}, please check the log",
traceback.format_exc(),
)
Utils.sendNotification(
f"⚠️ Error executing {currentAccount.username}, please check the log",
traceback.format_exc(),
True
)
continue
previous_points = previous_points_data.get(currentAccount.username, 0)

@@ -366,7 +366,6 @@ def save_previous_points_data(data):
main()
except Exception as e:
logging.exception("")
if Utils.loadConfig().get("apprise", {}).get("exceptions", True):
Utils.sendNotification(
"⚠️ Error occurred, please check the log", traceback.format_exc()
)
Utils.sendNotification(
"⚠️ Error occurred, please check the log", traceback.format_exc(), True
)
2 changes: 1 addition & 1 deletion src/browser.py
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ def getCCodeLang(lang: str, geo: str) -> tuple:
try:
nfo = ipapi.location()
except RateLimited:
geo = Utils.loadConfig().get("default_geolocation", "US").upper()
geo = Utils.loadConfig("config-private.yaml").get("default_geolocation", "US").upper()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is explicitly set, I think we should prefer it to the location based on IP.

logging.warning(f"Returning default geolocation {geo}", exc_info=True)
return "en", geo
if isinstance(nfo, dict):
2 changes: 1 addition & 1 deletion src/morePromotions.py
Original file line number Diff line number Diff line change
@@ -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 and Utils.loadConfig().get("apprise", {}).get("promotions", True):
if incompletePromotions and Utils.loadConfig().get("apprise", {}).get("notify", {}).get("incomplete-promotions", True):
Utils.sendNotification(f"Incomplete promotions(s) for {self.browser.username}", incompletePromotions)
logging.info("[MORE PROMOS] Exiting")
7 changes: 4 additions & 3 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -56,11 +56,12 @@ def loadConfig(configFilename="config.yaml") -> dict:
return {}

@staticmethod
def sendNotification(title, body) -> None:
if Utils.args.disable_apprise:
def sendNotification(title, body, is_exception=False) -> None:
is_exception_allowed = Utils.loadConfig().get("apprise", {}).get("notify", {}).get("uncaught-exceptions", True)
if Utils.args.disable_apprise or (is_exception and not is_exception_allowed):
return
apprise = Apprise()
urls: list[str] = Utils.loadConfig().get("apprise", {}).get("urls", [])
urls: list[str] = Utils.loadConfig("config-private.yaml").get("apprise", {}).get("urls", [])
if not urls:
logging.debug("No urls found, not sending notification")
return