Skip to content

Commit

Permalink
Provide default config if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
cal4 committed Jun 18, 2024
1 parent e3ea989 commit b3d1f48
Show file tree
Hide file tree
Showing 3 changed files with 310 additions and 325 deletions.
5 changes: 1 addition & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import atexit
import csv
import json
import logging
Expand All @@ -12,8 +11,6 @@
from datetime import datetime
from enum import Enum, auto

import psutil

from src import (
Browser,
Login,
Expand Down Expand Up @@ -269,7 +266,7 @@ def executeBot(currentAccount: Account, args: argparse.Namespace):
logging.info(
f"[POINTS] You are now at {utils.formatNumber(accountPointsCounter)} points !"
)
appriseSummary = AppriseSummary[utils.config["apprise"]["summary"]]
appriseSummary = AppriseSummary[utils.config.get("apprise", {}).get("summary", AppriseSummary.on_error.name)]
if appriseSummary == AppriseSummary.always:
goalNotifier = ""
if goalPoints > 0:
Expand Down
22 changes: 5 additions & 17 deletions src/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,12 @@ class AttemptsStrategy(Enum):
constant = auto()


DEFAULT_ATTEMPTS_MAX = 3
DEFAULT_BASE_DELAY = 900
DEFAULT_ATTEMPTS_STRATEGY = AttemptsStrategy.exponential.name


class Searches:
config = Utils.loadConfig()
# todo get rid of duplication, if possible
maxAttempts: int = config.get("attempts", DEFAULT_ATTEMPTS_MAX).get(
"max", DEFAULT_ATTEMPTS_MAX
)
baseDelay: int = config.get("attempts", DEFAULT_BASE_DELAY).get(
"base_delay_in_seconds", DEFAULT_BASE_DELAY
)
maxAttempts: int = config.get("attempts", {}).get("max", 6)
baseDelay: int = config.get("attempts", {}).get("base_delay_in_seconds", 60)
attemptsStrategy = AttemptsStrategy[
config.get("attempts", DEFAULT_ATTEMPTS_STRATEGY).get(
"strategy", DEFAULT_ATTEMPTS_STRATEGY
)
config.get("attempts", {}).get("strategy", AttemptsStrategy.exponential.name)
]
searchTerms: list[str] | None = None

Expand All @@ -61,7 +49,7 @@ def getGoogleTrends(self, wordsCount: int) -> list[str]:
i += 1
# Fetching daily trends from Google Trends API
r = requests.get(
f'https://trends.google.com/trends/api/dailytrends?hl={self.browser.localeLang}'
f"https://trends.google.com/trends/api/dailytrends?hl={self.browser.localeLang}"
f'&ed={(date.today() - timedelta(days=i)).strftime("%Y%m%d")}&geo={self.browser.localeGeo}&ns=15'
)
trends = json.loads(r.text[6:])
Expand All @@ -74,7 +62,7 @@ def getGoogleTrends(self, wordsCount: int) -> list[str]:
for relatedTopic in topic["relatedQueries"]
)
searchTerms = list(set(searchTerms))
del searchTerms[wordsCount: (len(searchTerms) + 1)]
del searchTerms[wordsCount : (len(searchTerms) + 1)]
return searchTerms

def getRelatedTerms(self, word: str) -> list[str]:
Expand Down
Loading

0 comments on commit b3d1f48

Please sign in to comment.