import json import os import pandas as pd files = [f for f in os.listdir('.') if f.endswith('.csv') and 'Pricelist' in f] order = ['LCD', 'BATERAI', 'KAMERA DEPAN', 'KAMERA BELAKANG', 'PORT CHARGER', 'SPEAKER', 'VOLUME', 'HOME BUTTON', 'ANTENA WIFI', 'TAPTIC', 'BACKGLASS', 'MESIN', 'SERVICE'] ordered_files = [] for name in order: for f in files: if name in f.upper(): ordered_files.append((name, f)) break all_services = [] for category, filename in ordered_files: df = pd.read_csv(filename) for _, row in df.iterrows(): seri = str(row.get('Seri', '')).strip() if 'IPHPNE' in seri.upper(): seri = seri.upper().replace('IPHPNE', 'IPHONE') produk = str(row.get('Produk', '')).strip() harga_raw = str(row.get('Harga', '')).strip() if pd.isna(row.get('Harga', '')) or harga_raw == "" or harga_raw == "nan": harga = "Hubungi Admin" elif "Rp" in harga_raw or "-" in harga_raw: harga = harga_raw else: try: num = int(float(harga_raw.replace('.', '').replace(',', ''))) harga = f"Rp {num:,}".replace(",", ".") except: harga = harga_raw garansi = str(row.get('Garansi', '')).strip() if pd.notna(row.get('Garansi', '')) else "-" ket = str(row.get('Keterangan', '')).strip() if pd.notna(row.get('Keterangan', '')) else "" if garansi == "nan": garansi = "-" if ket == "nan": ket = "" all_services.append({ 'seri': seri, 'nama': produk, 'kategori': category, 'harga': harga, 'garansi': garansi, 'keterangan': ket }) json_data = json.dumps(all_services, ensure_ascii=False, indent=2) template = """ """ output_code = template.replace("PLACEHOLDER_JSON", json_data) with open("PricelistFinal.txt", "w", encoding="utf-8") as f_out: f_out.write(output_code) print("Finished completely.")