diff --git a/README.md b/README.md index c1f64b9..eb1a7cf 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,10 @@ adjustments to this script appropriately rate-limit. ## Overview This is a simple web scraper for [chess.com](https://www.chess.com/coaches) -coaches. Running: -```bash -$> python3 main.py --user-agent -``` -will query [chess.com](https://www.chess.com) for all listed coach usernames as -well as specific information about each of corresponding coach (their profile, -recent activity, and stats). The result will be found in a newly created `data` -directory with the following structure: +coaches. The program searches for all listed coaches as well as specific +information about each of them (their profile, recent activity, and stats). The +result will be found in a newly created `data` directory with the following +structure: ``` data ├── coach @@ -29,12 +25,28 @@ data ├── ... ``` +## Usage + +If you have nix available, run: +```bash +$> nix build +$> result/bin/app --user-agent +``` +If not, ensure you have [poetry](https://python-poetry.org/) on your machine and +instead run the following: +```bash +$> poetry install +$> source $(poetry env info --path)/bin/activate +$> python3 -m app +``` + ## Development -This script was written using Python (version 3.11.6). Packaging and dependency -management relies on [poetry](https://python-poetry.org/) (version 1.7.0). -[direnv](https://direnv.net/) can be used to a launch a dev shell upon entering -this directory (refer to `.envrc`). Otherwise run via: +[nix](https://nixos.org/) is used for development. The included `flakes.nix` +file automatically loads in Python (version 3.11.6) with packaging and +dependency management handled by poetry (version 1.7.0). [direnv](https://direnv.net/) +can be used to a launch a dev shell upon entering this directory (refer to +`.envrc`). Otherwise run via: ```bash $> nix develop ``` diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__main__.py b/app/__main__.py new file mode 100644 index 0000000..b72dfcc --- /dev/null +++ b/app/__main__.py @@ -0,0 +1,5 @@ +from app import scraper + + +if __name__ == "__main__": + scraper.run() diff --git a/main.py b/app/scraper.py similarity index 99% rename from main.py rename to app/scraper.py index fc7e7fe..5feb2c5 100644 --- a/main.py +++ b/app/scraper.py @@ -171,7 +171,7 @@ async def _download_coach_data(session: aiohttp.ClientSession, username: str): print(f"Skipping {ANSI_COLOR(username)}") -async def scrape(): +async def _scrape(): parser = argparse.ArgumentParser( prog="chesscom-scraper", description="HTML scraping of chess.com coaches.", @@ -193,5 +193,5 @@ async def scrape(): await _download_coach_data(session, username) -def main(): - asyncio.run(scrape()) +def run(): + asyncio.run(_scrape()) diff --git a/flake.nix b/flake.nix index d8a4731..56818c6 100644 --- a/flake.nix +++ b/flake.nix @@ -68,6 +68,10 @@ projectDir = ./.; overrides = poetry2nix-overrides; preferWheels = true; + } // { + # These attributes are passed to `buildPythonApplication`. + pname = "app"; + version = "0.1.0"; }; default = self.packages.${system}.app; diff --git a/pyproject.toml b/pyproject.toml index c2725e3..5e13dbf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,3 +16,6 @@ types-beautifulsoup4 = "^4.12.0.7" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +app = "app.scraper:run"