Create revenue_tracker.py
Browse files- deployer/revenue_tracker.py +58 -0
deployer/revenue_tracker.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import zipfile
|
| 4 |
+
import datetime
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_revenue_stats():
|
| 8 |
+
"""
|
| 9 |
+
Returns a list of revenue and usage metrics for the past 7 days.
|
| 10 |
+
Each entry includes date, revenue_usd, active_users, and subscriptions.
|
| 11 |
+
"""
|
| 12 |
+
today = datetime.date.today()
|
| 13 |
+
stats = []
|
| 14 |
+
for i in range(7):
|
| 15 |
+
dt = today - datetime.timedelta(days=i)
|
| 16 |
+
stats.append({
|
| 17 |
+
"date": dt.isoformat(),
|
| 18 |
+
"revenue_usd": round(100 + i * 10, 2),
|
| 19 |
+
"active_users": 50 + i * 5,
|
| 20 |
+
"subscriptions": 10 + i
|
| 21 |
+
})
|
| 22 |
+
return stats
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def package_artifacts(assets):
|
| 26 |
+
"""
|
| 27 |
+
Packages generated app assets (blueprint and code files) into a zip archive.
|
| 28 |
+
Returns the path to the zip file.
|
| 29 |
+
"""
|
| 30 |
+
# Create a timestamped directory under /mnt/data
|
| 31 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
| 32 |
+
tmp_dir = f"/mnt/data/artifacts_{timestamp}"
|
| 33 |
+
os.makedirs(tmp_dir, exist_ok=True)
|
| 34 |
+
|
| 35 |
+
# Save blueprint as JSON
|
| 36 |
+
blueprint = assets.get("blueprint", {})
|
| 37 |
+
bp_path = os.path.join(tmp_dir, "blueprint.json")
|
| 38 |
+
with open(bp_path, "w") as f:
|
| 39 |
+
json.dump(blueprint, f, indent=2)
|
| 40 |
+
|
| 41 |
+
# Save each code file
|
| 42 |
+
code_files = assets.get("code", {})
|
| 43 |
+
for fname, content in code_files.items():
|
| 44 |
+
file_path = os.path.join(tmp_dir, fname)
|
| 45 |
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 46 |
+
with open(file_path, "w") as f:
|
| 47 |
+
f.write(content)
|
| 48 |
+
|
| 49 |
+
# Create zip archive
|
| 50 |
+
zip_path = f"{tmp_dir}.zip"
|
| 51 |
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 52 |
+
for root, _, files in os.walk(tmp_dir):
|
| 53 |
+
for file in files:
|
| 54 |
+
full = os.path.join(root, file)
|
| 55 |
+
rel = os.path.relpath(full, tmp_dir)
|
| 56 |
+
zipf.write(full, arcname=rel)
|
| 57 |
+
|
| 58 |
+
return zip_path
|