Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions scripts/generate_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,36 +84,40 @@ def generate_savings(cost_str):
return "100% of subscription cost"
return "100% of subscription cost"

output_data = []
def main():
output_data = []

# Load existing apps.json to preserve the original 5
existing_path = "src/data/apps.json"
if os.path.exists(existing_path):
with open(existing_path, "r") as f:
output_data = json.load(f)
# Load existing apps.json to preserve the original 5
existing_path = "src/data/apps.json"
if os.path.exists(existing_path):
with open(existing_path, "r") as f:
output_data = json.load(f)

existing_ids = set(app["id"] for app in output_data)
existing_ids = set(app["id"] for app in output_data)

for app in apps:
app_id = app["name"].lower().replace(" ", "-").replace(".", "")
if app_id in existing_ids:
continue

savings = generate_savings(app["cost"])

obj = {
"id": app_id,
"name": app["name"],
"category": app["category"],
"monthlyCost": app["cost"],
"replacement": app["replacement"],
"savings": savings,
"description": f"{app['name']} is a premium {app['category']} app for Shopify.",
"stackarchitectAlternativeLink": app["link"]
}
output_data.append(obj)
for app in apps:
app_id = app["name"].lower().replace(" ", "-").replace(".", "")
if app_id in existing_ids:
continue

savings = generate_savings(app["cost"])

obj = {
"id": app_id,
"name": app["name"],
"category": app["category"],
"monthlyCost": app["cost"],
"replacement": app["replacement"],
"savings": savings,
"description": f"{app['name']} is a premium {app['category']} app for Shopify.",
"stackarchitectAlternativeLink": app["link"]
}
output_data.append(obj)

with open(existing_path, "w") as f:
json.dump(output_data, f, indent=2)

with open(existing_path, "w") as f:
json.dump(output_data, f, indent=2)
print(f"Generated {len(output_data)} apps in {existing_path}")

print(f"Generated {len(output_data)} apps in {existing_path}")
if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions tests/scripts/test_generate_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
import sys
import os

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')))

from generate_apps import generate_savings

class TestGenerateSavings(unittest.TestCase):
def test_happy_paths(self):
self.assertEqual(generate_savings("$59+"), "$708/yr")
self.assertEqual(generate_savings("$1,000+"), "$12,000/yr")
self.assertEqual(generate_savings("$20"), "$240/yr")

def test_error_conditions(self):
self.assertEqual(generate_savings("$invalid"), "100% of subscription cost")
self.assertEqual(generate_savings("$100.50"), "100% of subscription cost")

def test_non_dollar_strings(self):
self.assertEqual(generate_savings("Free"), "100% of subscription cost")
self.assertEqual(generate_savings("Custom"), "100% of subscription cost")

if __name__ == '__main__':
unittest.main()