Files
boc/landvex-paket/integration.py
T
Bernt 6de2455917 v1.2.0: Add Global Markets footer, translated to 9 languages
- Added GLOBAL_MARKETS_TITLE to all translation files
- Updated footer with 12 markets (4 active + 8 upcoming)
- Translated market section to: zh-cn, zh-tw, ja, ko, th, vi, id, ms, hi
- Built and deployed to production
- CloudFront invalidation: I3RTMXVFDJXWLG3SYX208OP1CC
2026-07-08 19:56:03 +00:00

127 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""
LandveX API Integration — kopplar ihop Fas 1, 2, 3
"""
import requests
import json
BASE_URLS = {
"api": "http://localhost:8083",
"bounties": "http://localhost:8084",
"claims": "http://localhost:8085",
}
def search_objects(query: str):
"""Sök objekt i Fas 1 API"""
r = requests.get(f"{BASE_URLS['api']}/v0/search", params={"q": query})
return r.json()
def get_object(lvx_id: str):
"""Hämta objekt från Fas 1 API"""
r = requests.get(f"{BASE_URLS['api']}/v0/objects/{lvx_id}")
return r.json()
def create_bounty(title: str, description: str, reward: float = 0.0):
"""Skapa bounty i Fas 2 API"""
r = requests.post(
f"{BASE_URLS['bounties']}/v0/bounties",
json={"title": title, "description": description, "reward": reward},
)
return r.json()
def get_bounty(bounty_id: int):
"""Hämta bounty från Fas 2 API"""
r = requests.get(f"{BASE_URLS['bounties']}/v0/bounties/{bounty_id}")
return r.json()
def submit_bounty(bounty_id: int):
"""Skicka in bounty i Fas 2 API"""
r = requests.post(f"{BASE_URLS['bounties']}/v0/bounties/{bounty_id}/submit")
return r.json()
def create_claim(model_id: str, manufacturer_name: str, contact_email: str):
"""Skapa claim i Fas 3 API"""
r = requests.post(
f"{BASE_URLS['claims']}/v0/claims",
json={
"model_id": model_id,
"manufacturer_name": manufacturer_name,
"contact_email": contact_email,
},
)
return r.json()
def get_claim(claim_id: str):
"""Hämta claim från Fas 3 API"""
r = requests.get(f"{BASE_URLS['claims']}/v0/claims/{claim_id}")
return r.json()
def approve_claim(claim_id: str):
"""Godkänn claim i Fas 3 API"""
r = requests.post(f"{BASE_URLS['claims']}/v0/claims/{claim_id}/approve")
return r.json()
def full_workflow():
"""E2E-workflow: Sök → Bounty → Submit → Claim → Approve"""
print("=== LandveX E2E Workflow ===\n")
# 1. Sök efter objekt
print("1. Sök efter 'brunn':")
results = search_objects("brunn")
print(f" Hittade {results['count']} objekt")
if results["results"]:
obj = results["results"][0]
print(f" Första: {obj['lvx_id']} - {obj['namn_sv']}")
# 2. Skapa bounty
print("\n2. Skapa bounty:")
bounty = create_bounty(
title="Fotografera brunnsbetäckning",
description="Behöver bild på LVX-VAT-0101 för verifiering",
reward=50.0,
)
print(f" Bounty #{bounty['id']} skapad: {bounty['title']}")
# 3. Skicka in bounty (Zoomer har fotat)
print("\n3. Skicka in bounty:")
submitted = submit_bounty(bounty["id"])
print(f" Status: {submitted['status']}")
print(f" Inskickad: {submitted['submitted_at']}")
# 4. Skapa claim (tillverkare verifierar)
print("\n4. Skapa claim:")
claim = create_claim(
model_id="LVX-VAT-0101",
manufacturer_name="Svensk Brunnsindustri AB",
contact_email="info@brunnar.se",
)
print(f" Claim {claim['id'][:8]}... skapad")
print(f" Status: {claim['status']}")
# 5. Godkänn claim
print("\n5. Godkänn claim:")
approved = approve_claim(claim["id"])
print(f" Status: {approved['status']}")
print(f" Godkänd: {approved['approved_at']}")
print("\n=== Workflow complete ===")
return {
"bounty": bounty,
"claim": claim,
"approved": approved,
}
if __name__ == "__main__":
full_workflow()