jonathanjordan21 commited on
Commit
dee5397
·
verified ·
1 Parent(s): 6c84b4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -12
app.py CHANGED
@@ -606,6 +606,9 @@ class InputData(BaseModel):
606
  tarif_pkb: float = 0.015
607
  tarif_bbnkb: float = 0.1
608
 
 
 
 
609
  @app.post("/pred")
610
  async def greet_json(body: InputData):
611
  global codes_emb
@@ -745,17 +748,6 @@ async def greet_json(body: InputData):
745
 
746
  @app.get("/get_data")
747
  def get_data(nopol: str):
748
- # print(nopol)
749
- # options = webdriver.ChromeOptions()
750
- # options.add_argument("--headless")
751
- # options.add_argument("--disable-gpu")
752
- # options.add_argument("--no-sandbox")
753
- # options.add_argument('--disable-dev-shm-usage')
754
- # options.binary_location = "/usr/bin/chromium"
755
- # # driver = webdriver.Chrome(options=options)
756
- # # driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
757
- # driver = webdriver.Chrome(executable_path="/usr/lib/chromium/chromedriver", options=options)
758
-
759
  data_kendaraan, total_tagihan, rincians_pkb, rincians_swd = get_vehicle_info_bs4(nopol)
760
  data_kendaraan["no_polisi"] = nopol
761
  return {
@@ -763,4 +755,55 @@ def get_data(nopol: str):
763
  "rincian_total_tagihan":total_tagihan,
764
  "rincian_pkb":[x for x in rincians_pkb if any(x.values())],
765
  "rincian_swdkllj":[x for x in rincians_swd if any(x.values())]
766
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  tarif_pkb: float = 0.015
607
  tarif_bbnkb: float = 0.1
608
 
609
+ # class InputGetData(BaseModel):
610
+ # nopol: message
611
+
612
  @app.post("/pred")
613
  async def greet_json(body: InputData):
614
  global codes_emb
 
748
 
749
  @app.get("/get_data")
750
  def get_data(nopol: str):
 
 
 
 
 
 
 
 
 
 
 
751
  data_kendaraan, total_tagihan, rincians_pkb, rincians_swd = get_vehicle_info_bs4(nopol)
752
  data_kendaraan["no_polisi"] = nopol
753
  return {
 
755
  "rincian_total_tagihan":total_tagihan,
756
  "rincian_pkb":[x for x in rincians_pkb if any(x.values())],
757
  "rincian_swdkllj":[x for x in rincians_swd if any(x.values())]
758
+ }
759
+
760
+
761
+ @app.post("/get_data")
762
+ async def get_data_json(body: InputData):
763
+ message = body.message
764
+
765
+ data_kendaraan, total_tagihan, rincians_pkb, rincians_swd = get_vehicle_info_bs4(message)
766
+ data_kendaraan["no_polisi"] = nopol
767
+
768
+ string = "*DATA KENDARAAN:*\n"
769
+ string += "\n".join([f"{k.replace("_", " ").upper()} \t\t\t: {v}" for k,v in data_kendaraan.items()])
770
+ string += "\n\n---"
771
+
772
+ string += "*RINCIAN:*\n"
773
+ string += "".join([f"{x['jenis']}:\nPokok: Rp{x['pokok']}\nDenda: Rp{x['denda']}\nTotal: Rp{x['total']}\n---" for x in total_tagihan])
774
+
775
+ string += "\n*Rincian PKB:*\n"
776
+ string+= "".join(
777
+ [
778
+ f"{x['jenis']}:\nPokok: Rp{x['pokok']}\nDenda: Rp{x['denda']}\nTotal: Rp{x['total']}\n---"
779
+ for x in rincians_pkb
780
+ if str(x.get("total", 0)) != "0"
781
+ ]
782
+ )
783
+
784
+ string += "\n*Rincian SWDKLLJ:*\n"
785
+ string+= "".join(
786
+ [
787
+ f"{x['jenis']}:\nPokok: Rp{x['pokok']}\nDenda: Rp{x['denda']}\nTotal: Rp{x['total']}\n---"
788
+ for x in rincians_swd
789
+ if str(x.get("total", 0)) != "0"
790
+ ]
791
+ )
792
+
793
+ return {
794
+ "code":200,
795
+ "success":True,
796
+ "message":"Request was successful",
797
+ "data":{"results":{"text":string}},
798
+ }
799
+
800
+
801
+
802
+ # return {
803
+ # "data_kendaraan":data_kendaraan,
804
+ # "rincian_total_tagihan":total_tagihan,
805
+ # "rincian_pkb":[x for x in rincians_pkb if str(x.get("total", 0)) != "0"],
806
+ # "rincian_swdkllj":[x for x in rincians_swd if str(x.get("total", 0)) != "0"]
807
+ # }
808
+
809
+