Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
refactor!: bump deps, refactored config format for some fields (break…
Browse files Browse the repository at this point in the history
…ing change)
  • Loading branch information
totoroterror committed Dec 7, 2023
1 parent 92f7080 commit 7722d4b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BASE_KEYS=
# BASE_KEYS=[""]
THREADS_COUNT=1
# PROXY_FILE=
DELAY=25
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ With this script you will be able to clone many 12-24 PB keys.

## Configuration

- `BASE_KEYS` (not required) - keys to clone divided by comma, if none then default keys will be used (script may not work with default keys)
- `BASE_KEYS` (not required) - keys to clone divided as array in JSON format (ex: `["key1", "key2"]`), if none then default keys will be used (script may not work with default keys)
- `THREADS_COUNT` (default: `1`) - amount of threads.
- `DEVICE_MODELS` (not required) - custom device model names divided by comma
- `DEVICE_MODELS` (not required) - custom device model names divided as array in JSON format (ex: `["Android", "Secret Device"]`)
- `SAVE_WIREGUARD_VARIABLES` (default: false) - should script get variables that are required to generate WireGuard config (peer ips, private / public key, endpoint)?
- `PROXY_FILE` (not required) - path to proxy file, if none then script will be launched in proxyless mode.
- `DELAY` (default: `25`) - seconds to sleep after key clone
Expand Down
17 changes: 9 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
aiodns~=3.0.0
aiohttp~=3.8.5
aiohttp-socks~=0.7.1
loguru~=0.6.0
pydantic~=1.10.2
python-dotenv~=0.21.0
typing_extensions~=4.4.0
cryptography~=41.0.3
aiodns~=3.1.1
aiohttp~=3.9.1
aiohttp-socks~=0.8.4
loguru~=0.7.2
pydantic~=2.5.2
pydantic-settings~=2.1.0
python-dotenv~=1.0.0
typing_extensions~=4.8.0
cryptography~=41.0.7
39 changes: 16 additions & 23 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any
from pydantic import BaseSettings, Field

from pydantic import Field
from pydantic_settings import (
BaseSettings,
SettingsConfigDict,
)

class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')

BASE_KEYS: list[str] = Field(
env='BASE_KEYS',
validation_alias='BASE_KEYS',
default=[
'4QSK31f5-gf7624vG-AK5E2c60',
'158yuMs0-aQ0H84j9-85zCub93',
Expand All @@ -18,25 +22,14 @@ class Settings(BaseSettings):
'Tw36cx85-4Vq5GA08-GP835x1k',
]
)
THREADS_COUNT: int = Field(env='THREADS_COUNT', default=1)
PROXY_FILE: str | None = Field(env='PROXY_FILE', default=None)
DEVICE_MODELS: list[str] = Field(env='DEVICE_MODELS', default=[])
SAVE_WIREGUARD_VARIABLES: bool = Field(env='SAVE_WIREGUARD_VARIABLES', default=False)
DELAY: int = Field(env='DELAY', default=25)
OUTPUT_FILE: str = Field(env='OUTPUT_FILE', default='output.txt')
OUTPUT_FORMAT: str = Field(env='OUTPUT_FORMAT', default='{key} | {referral_count}')
RETRY_COUNT: int = Field(env='RETRY_COUNT', default=3)

class Config:
env_file = '.env'
env_file_encoding = 'utf-8'

@classmethod
def parse_env_var(cls, field: str, raw_val: str) -> Any:
if field == 'BASE_KEYS' or field == 'DEVICE_MODELS':
if isinstance(raw_val, str):
return str(raw_val).split(',')
THREADS_COUNT: int = Field(validation_alias='THREADS_COUNT', default=1)
PROXY_FILE: str | None = Field(validation_alias='PROXY_FILE', default=None)
DEVICE_MODELS: list[str] = Field(validation_alias='DEVICE_MODELS', default=[])
SAVE_WIREGUARD_VARIABLES: bool = Field(validation_alias='SAVE_WIREGUARD_VARIABLES', default=False)
DELAY: int = Field(validation_alias='DELAY', default=25)
OUTPUT_FILE: str = Field(validation_alias='OUTPUT_FILE', default='output.txt')
OUTPUT_FORMAT: str = Field(validation_alias='OUTPUT_FORMAT', default='{key} | {referral_count}')
RETRY_COUNT: int = Field(validation_alias='RETRY_COUNT', default=3)

return cls.json_loads(raw_val) # type: ignore

config = Settings()

0 comments on commit 7722d4b

Please sign in to comment.