-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsales_report.py
More file actions
50 lines (39 loc) · 1.84 KB
/
sales_report.py
File metadata and controls
50 lines (39 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Generate a sales summary report from JSON data.
Usage: python sales_report.py
"""
import requests
import json
API_URL = "https://reportforge-api.vercel.app/api/json-to-report"
sales_data = [
{"product": "Widget Pro", "region": "North America", "revenue": 45200, "units": 904, "rep": "Alice Chen"},
{"product": "Widget Lite", "region": "North America", "revenue": 12800, "units": 640, "rep": "Bob Johnson"},
{"product": "Widget Pro", "region": "Europe", "revenue": 38500, "units": 770, "rep": "Carol Williams"},
{"product": "Widget Lite", "region": "Europe", "revenue": 9600, "units": 480, "rep": "Dave Brown"},
{"product": "Widget Pro", "region": "Asia Pacific", "revenue": 52100, "units": 1042, "rep": "Eve Davis"},
{"product": "Widget Lite", "region": "Asia Pacific", "revenue": 15300, "units": 765, "rep": "Frank Wilson"},
{"product": "Widget Enterprise", "region": "North America", "revenue": 89000, "units": 178, "rep": "Alice Chen"},
{"product": "Widget Enterprise", "region": "Europe", "revenue": 67500, "units": 135, "rep": "Carol Williams"},
]
def generate_report():
response = requests.post(
API_URL,
json={"data": sales_data, "template": "sales-summary"},
)
if response.status_code != 200:
print(f"Error: {response.status_code}")
print(response.text)
return
result = response.json()
# Print metadata
print(f"Template: {result['meta']['template']}")
print(f"Rows: {result['meta']['rowCount']}")
print(f"Columns: {', '.join(result['meta']['columns'])}")
# Save HTML report
filename = "sales-report.html"
with open(filename, "w", encoding="utf-8") as f:
f.write(result["html"])
print(f"\nReport saved to {filename}")
print("Open it in your browser to see the styled report.")
if __name__ == "__main__":
generate_report()