File size: 2,773 Bytes
b84ea83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Populate physical location data for the 7 Kopkit outlets.

Run once:
    cd python
    .\venv\Scripts\python.exe scripts\populate_locations.py
"""

import asyncio
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from dotenv import load_dotenv
load_dotenv(os.path.join(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))), ".env"
))

from sqlalchemy import update
from config.database_config import async_session_factory, init_db
from models.outlet_model import Outlet

# ── Location data for each Kopkit branch ─────────────────────────────────────

LOCATIONS = {
    "Kopkit Jati": {
        "location": "Jl. Jati, Padang Timur, Kota Padang",
        "description": "Outlet di area Jati, kawasan kampus dan perkantoran Padang Timur.",
    },
    "Kopkit Veteran": {
        "location": "Jl. Veteran, Padang Utara, Kota Padang",
        "description": "Outlet di Jl. Veteran, area perumahan dan komersial Padang Utara.",
    },
    "Kopkit Ulak Karang": {
        "location": "Ulak Karang, Padang Utara, Kota Padang",
        "description": "Outlet di kawasan Ulak Karang, area hunian padat dan komersial.",
    },
    "Kopkit Sutomo": {
        "location": "Jl. Sutomo, Padang Selatan, Kota Padang",
        "description": "Outlet di Jl. Sutomo, pusat kota dekat area perdagangan.",
    },
    "Kopkit Gunung Pangilun": {
        "location": "Gunung Pangilun, Padang Utara, Kota Padang",
        "description": "Outlet di area Gunung Pangilun, kawasan wisata dan rekreasi.",
    },
    "Kopkit Fabriek Bloc Tabing": {
        "location": "Fabriek Bloc, Tabing, Koto Tangah, Kota Padang",
        "description": "Outlet di kompleks Fabriek Bloc Tabing, area co-working dan kreatif.",
    },
    "Kopkit Pondok": {
        "location": "Pondok, Kota Padang",
        "description": "Outlet di kawasan Pondok, area residensial kota Padang.",
    },
}


async def main():
    await init_db()
    async with async_session_factory() as db:
        updated = 0
        for name, data in LOCATIONS.items():
            result = await db.execute(
                update(Outlet)
                .where(Outlet.name == name)
                .values(
                    location=data["location"],
                    description=data["description"],
                )
            )
            if result.rowcount > 0:
                updated += 1
                print(f"  [OK] {name} -> {data['location']}")
            else:
                print(f"  [--] {name} not found in DB (skipped)")

        await db.commit()
        print(f"\nUpdated {updated}/{len(LOCATIONS)} outlets.")


if __name__ == "__main__":
    asyncio.run(main())