Skip to content

Commit 328ef4d

Browse files
Merge branch 'main' into pylint
Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com>
2 parents efc6a58 + 64f0496 commit 328ef4d

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.

css-reports/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ async def fetch_customisation_report():
2929
start_date: str | None = request.args.get("start_date")
3030
end_date: str | None = request.args.get("end_date")
3131

32-
# print("Auth cookie: " + auth_cookie)
3332
print(f"Organisation ID: {organisation_id}")
3433
print(f"Product Name: {product_name}")
3534

css-reports/report.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,16 @@ async def fetch_report_url_and_cookies(
105105
headers=BASE_HEADERS,
106106
cookies=cookies,
107107
)
108-
async with (
109-
session_v2,
110-
session_v2.post(url=SALES_REPORTS_URL, data=data_fields) as http_response,
111-
):
108+
109+
async with (session_v2, session_v2.post(url=SALES_REPORTS_URL, data=data_fields) as http_response): # noqa: E501
110+
112111
if http_response.status != 200:
113112
print("Returned a non 200 status code!!")
114113
print(http_response)
115114
return None, {}
116115

117116
response_html: str = await http_response.text()
118117

119-
# get the report viewer div
120118
soup = BeautifulSoup(response_html, "html.parser")
121119
report_viewer_div: bs4.PageElement | bs4.Tag | bs4.NavigableString | None = (
122120
soup.find("div", {"id": "report_viewer_wrapper"})

0 commit comments

Comments
 (0)