-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
861f806
commit c2ee6bf
Showing
7 changed files
with
541 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from os import getenv | ||
from dotenv import load_dotenv | ||
from dataclasses import dataclass | ||
load_dotenv() | ||
|
||
|
||
@dataclass(frozen=True, slots=True) | ||
class Config: | ||
min_coc_email = 1 | ||
max_coc_email = 12 | ||
coc_password = getenv("COC_PASSWORD") | ||
|
||
secondary_loop_change = 15 | ||
tertiary_loop_change = 150 | ||
max_tag_split = 50_000 | ||
|
||
static_mongodb = getenv("STATIC_MONGODB") | ||
stats_mongodb = getenv("STATS_MONGODB") | ||
redis_ip = getenv("REDIS_IP") | ||
redis_pw = getenv("REDIS_PW") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import motor.motor_asyncio | ||
import asyncio | ||
|
||
from collections import deque | ||
from redis import asyncio as redis | ||
from .config import Config | ||
from .tracking import main | ||
from ..utils import create_keys | ||
|
||
|
||
if __name__ == '__main__': | ||
config = Config() | ||
loop = asyncio.get_event_loop() | ||
|
||
stats_mongo_client = motor.motor_asyncio.AsyncIOMotorClient(config.stats_mongodb) | ||
static_mongo_client = motor.motor_asyncio.AsyncIOMotorClient(config.static_mongodb) | ||
|
||
redis_host = redis.Redis(host=config.redis_ip, port=6379, db=0, password=config.redis_pw, decode_responses=False, max_connections=2500) | ||
keys = create_keys([f"apiclashofclans+test{x}@gmail.com" for x in range(config.min_coc_email, config.max_coc_email + 1)], [config.coc_password] * config.max_coc_email) | ||
keys = deque(keys) | ||
loop.create_task(main(keys=keys, cache=redis_host, stats_mongo_client=stats_mongo_client, static_mongo_client=static_mongo_client)) | ||
loop.run_forever() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from msgspec import Struct | ||
import pendulum as pend | ||
from datetime import timedelta | ||
import coc | ||
|
||
def gen_raid_date(): | ||
now = pend.now(tz=pend.UTC) | ||
current_dayofweek = now.weekday() | ||
if (current_dayofweek == 4 and now.hour >= 7) or (current_dayofweek == 5) or (current_dayofweek == 6) or ( | ||
current_dayofweek == 0 and now.hour < 7): | ||
if current_dayofweek == 0: | ||
current_dayofweek = 7 | ||
fallback = current_dayofweek - 4 | ||
raidDate = (now - timedelta(fallback)).date() | ||
return str(raidDate) | ||
else: | ||
forward = 4 - current_dayofweek | ||
raidDate = (now + timedelta(forward)).date() | ||
return str(raidDate) | ||
|
||
def gen_season_date(): | ||
end = coc.utils.get_season_end().replace(tzinfo=pend.UTC).date() | ||
month = end.month | ||
if month <= 9: | ||
month = f"0{month}" | ||
return f"{end.year}-{month}" | ||
|
||
def gen_legend_date(): | ||
now = pend.now(tz=pend.UTC) | ||
hour = now.hour | ||
if hour < 5: | ||
date = (now - timedelta(1)).date() | ||
else: | ||
date = now.date() | ||
return str(date) | ||
|
||
def gen_games_season(): | ||
now = pend.now(tz=pend.UTC) | ||
month = now.month | ||
if month <= 9: | ||
month = f"0{month}" | ||
return f"{now.year}-{month}" | ||
|
||
def get_player_changes(previous_response: dict, response: dict): | ||
new_json = {} | ||
fields_to_update = [] | ||
ok_achievements = {"Gold Grab", "Elixir Escapade", "Heroic Heist", "Games Champion", "Aggressive Capitalism", | ||
"Well Seasoned", "Nice and Tidy", "War League Legend", "Wall Buster"} | ||
for key, item in response.items(): | ||
old_item = previous_response.get(key) | ||
if old_item != item: | ||
fields_to_update.append(key) | ||
not_ok_fields = {"labels", "legendStatistics", "playerHouse", "versusBattleWinCount"} | ||
if key in not_ok_fields: | ||
continue | ||
if old_item != item: | ||
if isinstance(item, list): | ||
for count, spot in enumerate(item): | ||
spot_name = spot["name"] | ||
if key == "achievements" and spot_name not in ok_achievements: | ||
continue | ||
old_ = next((item for item in old_item if item["name"] == spot_name), None) | ||
if old_ != spot: | ||
if key == "achievements": | ||
if old_ is not None: | ||
new_json[(key, spot_name.replace(".", ""))] = (old_["value"], spot["value"]) | ||
else: | ||
new_json[(key, spot_name.replace(".", ""))] = (None, spot["value"]) | ||
else: | ||
if old_ is not None: | ||
new_json[(key, spot_name.replace(".", ""))] = (old_["level"], spot["level"]) | ||
else: | ||
new_json[(key, spot_name.replace(".", ""))] = (None, spot["level"]) | ||
else: | ||
if key == "clan": | ||
new_json[(key, key)] = (None, {"tag": item["tag"], "name": item["name"]}) | ||
elif key == "league": | ||
new_json[(key, key)] = (None, {"tag": item["id"], "name": item["name"]}) | ||
else: | ||
new_json[(key, key)] = (old_item, item) | ||
|
||
return (new_json, fields_to_update) | ||
|
||
|
||
class Player(Struct): | ||
tag: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters