|
| 1 | +# Guild Customisation Report Fetcher |
| 2 | + |
| 3 | +This project provides a Flask-based web API to fetch customisation, purchaser, or sales reports from the Guild website. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Python 3.12+ (or use Docker) |
| 8 | +- `pip` for installing dependencies |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +### 1. Install Dependencies |
| 13 | + |
| 14 | +If running locally, install the required Python packages: |
| 15 | + |
| 16 | +```sh |
| 17 | +pip install -r requirements.txt |
| 18 | +``` |
| 19 | + |
| 20 | +### 2. Environment |
| 21 | + |
| 22 | +No special environment variables are required. You will need a valid `auth_cookie` for the Guild website. |
| 23 | + |
| 24 | +## Running the Server |
| 25 | + |
| 26 | +### Option 1: Locally |
| 27 | + |
| 28 | +Run the Flask app: |
| 29 | + |
| 30 | +```sh |
| 31 | +python app.py |
| 32 | +``` |
| 33 | + |
| 34 | +The server will start on `http://0.0.0.0:8000`. |
| 35 | + |
| 36 | +### Option 2: Using Docker |
| 37 | + |
| 38 | +Build and run the Docker container: |
| 39 | + |
| 40 | +```sh |
| 41 | +docker build -t css-reports . |
| 42 | +docker run -p 8000:8000 css-reports |
| 43 | +``` |
| 44 | + |
| 45 | +## API Usage |
| 46 | + |
| 47 | +### Endpoint |
| 48 | + |
| 49 | +```http |
| 50 | +GET /customisation_report |
| 51 | +``` |
| 52 | + |
| 53 | +### Query Parameters |
| 54 | + |
| 55 | +- `auth_cookie` (required): Authentication cookie for the Guild website. |
| 56 | +- `organisation_id` (required): Organisation ID for the report. |
| 57 | +- `report_type` (optional): One of `Customisations`, `Purchasers`, or `Sales`. Defaults to `Customisations`. |
| 58 | +- `product_name` or `product_names` (required): Name or ID of the product to filter. |
| 59 | +- `start_date` (optional): Start date in `YYYY-MM-DD` format. Defaults to `2000-01-01`. |
| 60 | +- `end_date` (optional): End date in `YYYY-MM-DD` format. Defaults to `2100-01-01`. |
| 61 | + |
| 62 | +**Note:** You must provide either `product_name` or `product_names`, but not both. |
| 63 | + |
| 64 | +### Example Request |
| 65 | + |
| 66 | +```sh |
| 67 | +curl "http://localhost:8000/customisation_report?auth_cookie=YOUR_COOKIE&organisation_id=1234&product_name=Hoodie&start_date=2024-01-01&end_date=2024-12-31" |
| 68 | +``` |
| 69 | + |
| 70 | +This will return a CSV file as a download containing the requested report. |
| 71 | + |
| 72 | +### Error Handling |
| 73 | + |
| 74 | +- Returns HTTP 400 for missing or invalid parameters. |
| 75 | +- Returns HTTP 500 for server or report generation errors. |
| 76 | + |
| 77 | +## Other Endpoints |
| 78 | + |
| 79 | +- `/` and any unknown route: Redirects to https://cssbham.com |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +**Tip:** For production, consider using a WSGI server like `waitress` or `gunicorn` instead of Flask's built-in server. |
0 commit comments