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 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
10 changes: 5 additions & 5 deletions .template-config-private.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# config-private.yaml
# Copy this file to config-private.yaml to use
apprise:
urls:
- 'discord://WebhookID/WebhookToken' # Replace with your actual Apprise service URLs
# 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

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 `.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.

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
4 changes: 4 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +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
14 changes: 12 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def main():
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)
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 @@ -357,5 +367,5 @@ def save_previous_points_data(data):
except Exception as e:
logging.exception("")
Utils.sendNotification(
"⚠️ Error occurred, please check the log", traceback.format_exc()
"⚠️ Error occurred, please check the log", traceback.format_exc(), True
)
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("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):
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("notify", {}).get("incomplete-promotions", True):
Utils.sendNotification(f"Incomplete promotions(s) for {self.browser.username}", incompletePromotions)
logging.info("[MORE PROMOS] Exiting")
5 changes: 3 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ 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("config-private.yaml").get("apprise", {}).get("urls", [])
Expand Down