Ninad077 commited on
Commit
aa1770c
·
verified ·
1 Parent(s): 1eb0272

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +167 -23
app.py CHANGED
@@ -6,6 +6,9 @@ import configparser # For activating the config
6
  from PIL import Image, ImageFilter
7
  import io
8
  import base64
 
 
 
9
 
10
  global_user_data = [] # For appending user_data
11
  global_data_rows = [] # For appending data rows
@@ -556,29 +559,29 @@ if bundle_by == "Feature specific":
556
  if st.button("Submit", key ='submit_button'):
557
  # Save user data
558
  user_data = {
559
- "Business Head": business_head,
560
- "Company ID": company_id,
561
- "Company Name": company_name,
562
  "Currency": currency,
563
- "Bundle by": bundle_by,
564
- "Plan Name": plan_name,
565
- "Plan Description": plan_description,
566
- "Product lines": ordering_channels,
567
- "Fulfilling Location": fulfilling_location,
568
- "Application ID": application_id,
569
- "Fee Type": selected_fee_type,
570
- "Variable Type": selected_variable_type,
571
- "Chargeable on": selected_chargeable_on,
572
- "Fee Nature": selected_fee_nature,
573
- "Commercial value": user_input_3,
574
- "Fee reversal": 0,
575
- "Reversal %": 0,
576
- "Usage limit": usage_3,
577
- "Threshold value": Capping_or_Minimum_Guarantee_3,
578
- "Threshold option": threshold,
579
- "Expected Billing": expected_billing,
580
- "Plan Validity": selected_plan_validity,
581
- "Payment Method": selected_payment_method,
582
  }
583
 
584
  global_user_data.append((user_name, user_data))
@@ -596,6 +599,76 @@ if bundle_by == "Feature specific":
596
  # Display saved records
597
  display_saved_records()
598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
 
600
 
601
  elif bundle_by == "Single value":
@@ -809,6 +882,7 @@ elif bundle_by == "Single value":
809
  "Expected Billing": user_input_3,
810
  "Plan Validity": selected_plan_validity,
811
  "Payment Method": selected_payment_method,
 
812
  }
813
 
814
  global_user_data.append((user_name, user_data))
@@ -826,4 +900,74 @@ elif bundle_by == "Single value":
826
  # Display saved records
827
  display_saved_records()
828
 
829
- # Exporting the data to BQ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  from PIL import Image, ImageFilter
7
  import io
8
  import base64
9
+ from google.cloud import bigquery
10
+ from google.oauth2 import service_account
11
+
12
 
13
  global_user_data = [] # For appending user_data
14
  global_data_rows = [] # For appending data rows
 
559
  if st.button("Submit", key ='submit_button'):
560
  # Save user data
561
  user_data = {
562
+ "Business_Head": business_head,
563
+ "Company_ID": company_id,
564
+ "Company_Name": company_name,
565
  "Currency": currency,
566
+ "Bundle_by": bundle_by,
567
+ "Plan_Name": plan_name,
568
+ "Plan_Description": plan_description,
569
+ "Product_lines": ordering_channels,
570
+ "Fulfilling_Location": fulfilling_location,
571
+ "Application_ID": application_id,
572
+ "Fee_Type": selected_fee_type,
573
+ "Variable_Type": selected_variable_type,
574
+ "Chargeable_on": selected_chargeable_on,
575
+ "Fee_Nature": selected_fee_nature,
576
+ "Commercial_value": user_input_3,
577
+ "Fee_reversal": 0,
578
+ "Reversal_%": 0,
579
+ "Usage_limit": usage_3,
580
+ "Threshold_value": Capping_or_Minimum_Guarantee_3,
581
+ "Threshold_option": threshold,
582
+ "Expected_Billing": expected_billing,
583
+ "Payment_Method": selected_payment_method,
584
+ "Plan_Validity": selected_plan_validity,
585
  }
586
 
587
  global_user_data.append((user_name, user_data))
 
599
  # Display saved records
600
  display_saved_records()
601
 
602
+ if st.button("Export data to BQ"):
603
+ from google.oauth2 import service_account
604
+ from google.cloud import bigquery
605
+
606
+ def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
607
+ # Use from_service_account_info instead of from_service_account_file
608
+ credentials = service_account.Credentials.from_service_account_info(service_account_info)
609
+
610
+ # Initialize a BigQuery client
611
+ client = bigquery.Client(credentials=credentials, project=project_id)
612
+
613
+ # Specify the table reference
614
+ table_ref = f"{project_id}.{dataset_id}.{table_id}"
615
+ table = client.get_table(table_ref)
616
+
617
+ # Insert form data into the table
618
+ rows_to_insert = [user_data]
619
+ errors = client.insert_rows_json(table, rows_to_insert)
620
+
621
+ if errors:
622
+ print(f"Errors occurred while inserting rows: {errors}")
623
+ else:
624
+ print("Insert successful")
625
+
626
+ project_id = "fynd-db"
627
+ dataset_id = "finance_dwh"
628
+ table_id = "plan_v2"
629
+ user_data = {
630
+ "Business_Head": business_head,
631
+ "Company_ID": company_id,
632
+ "Company_Name": company_name,
633
+ "Currency": currency,
634
+ "Bundle_by": bundle_by,
635
+ "Plan_Name": plan_name,
636
+ "Plan_Description": plan_description,
637
+ "Product_lines": ordering_channels,
638
+ "Fulfilling_Location": fulfilling_location,
639
+ "Application_ID": application_id,
640
+ "Fee_Type": selected_fee_type,
641
+ "Variable_Type": selected_variable_type,
642
+ "Chargeable_on": selected_chargeable_on,
643
+ "Fee_Nature": "Flat currency",
644
+ "Commercial_value": user_input_3,
645
+ "Fee_reversal": 0,
646
+ "Reversal_%": 0,
647
+ "Usage_limit": usage_3,
648
+ "Threshold_value": Capping_or_Minimum_Guarantee_3,
649
+ "Threshold_option": threshold,
650
+ "Expected_Billing": expected_billing,
651
+ "Payment_Method": selected_payment_method,
652
+ "Plan_Validity": selected_plan_validity
653
+ }
654
+
655
+ service_account_info = {
656
+ "type": "service_account",
657
+ "project_id": "fynd-db",
658
+ "private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
659
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v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1qC4tP/16YMpaVU8qjY7ZdfB2b75lgdaT\npZLOxZsq9X8Xauso8uxv+nDCG/8YtmEV9d61u0acE+t+mA3PVxqkZ0m/AoGBAI5c\nY76AqeN+JVxaEm/0tIsj9Om46hR2URJ2lzB6YCuzINUqy9GjHJBWj9oITzD2FmNV\n/yCGIeW3CClOyCtzJyNLhYf5Sr+XjoKRQVN/+7+C/l2YL6Sg4Ok/PRMm6iH+u2QB\nJTY1d0pOdfUPqR8gKsVJgBGE04iwE/RmLpp9/XZRAoGAFtaa9JeHk9dmZiST3lev\ns5syeOK1cCj1+nJer/GPEjqWMKxbCULvoEYBp7RaoEXjfGi7P4Mc6YHnbljHc+sL\niJzHhxrv/HYZdlCdTU3IRWT0sNHzqZemfYnsVTSp+4y61sGDxioDYL4CLnMq5T2F\nqzfc2qp3s8ApVloY3giuqnI=\n-----END PRIVATE KEY-----\n",
660
+ "client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
661
+ "client_id": "114883060650442183907",
662
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
663
+ "token_uri": "https://oauth2.googleapis.com/token",
664
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
665
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
666
+ "universe_domain": "googleapis.com"
667
+ }
668
+
669
+ insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
670
+
671
+
672
 
673
 
674
  elif bundle_by == "Single value":
 
882
  "Expected Billing": user_input_3,
883
  "Plan Validity": selected_plan_validity,
884
  "Payment Method": selected_payment_method,
885
+
886
  }
887
 
888
  global_user_data.append((user_name, user_data))
 
900
  # Display saved records
901
  display_saved_records()
902
 
903
+
904
+ if st.button("Export data to BQ"):
905
+
906
+ from google.oauth2 import service_account
907
+ from google.cloud import bigquery
908
+
909
+ def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
910
+ # Use from_service_account_info instead of from_service_account_file
911
+ credentials = service_account.Credentials.from_service_account_info(service_account_info)
912
+
913
+ # Initialize a BigQuery client
914
+ client = bigquery.Client(credentials=credentials, project=project_id)
915
+
916
+ # Specify the table reference
917
+ table_ref = f"{project_id}.{dataset_id}.{table_id}"
918
+ table = client.get_table(table_ref)
919
+
920
+ # Insert form data into the table
921
+ rows_to_insert = [user_data]
922
+ errors = client.insert_rows_json(table, rows_to_insert)
923
+
924
+ if errors:
925
+ print(f"Errors occurred while inserting rows: {errors}")
926
+ else:
927
+ print("Insert successful")
928
+
929
+ project_id = "fynd-db"
930
+ dataset_id = "finance_dwh"
931
+ table_id = "plan_v2"
932
+ user_data = {
933
+ "Business_Head": business_head,
934
+ "Company_ID": company_id,
935
+ "Company_Name": company_name,
936
+ "Currency": currency,
937
+ "Bundle_by": bundle_by,
938
+ "Plan_Name": plan_name,
939
+ "Plan_Description": plan_description,
940
+ "Product_lines": ordering_channels,
941
+ "Fulfilling_Location": fulfilling_location,
942
+ "Application_ID": application_id,
943
+ "Fee_Type": selected_fee_type,
944
+ "Variable_Type": selected_variable_type,
945
+ "Chargeable_on": selected_chargeable_on,
946
+ "Fee_Nature": "Flat currency",
947
+ "Commercial_value": user_input_3,
948
+ "Fee_reversal": 0,
949
+ "Reversal_%": 0,
950
+ "Usage_limit": usage_3,
951
+ "Threshold_value": 0,
952
+ "Threshold_option": 0,
953
+ "Expected_Billing": user_input_3,
954
+ "Payment_Method": selected_payment_method,
955
+ "Plan_Validity": selected_plan_validity
956
+
957
+ }
958
+
959
+ service_account_info = {
960
+ "type": "service_account",
961
+ "project_id": "fynd-db",
962
+ "private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
963
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deT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oipUmxcX34M/Eiq4u8Xp1qC4tP/16YMpaVU8qjY7ZdfB2b75lgdaT\npZLOxZsq9X8Xauso8uxv+nDCG/8YtmEV9d61u0acE+t+mA3PVxqkZ0m/AoGBAI5c\nY76AqeN+JVxaEm/0tIsj9Om46hR2URJ2lzB6YCuzINUqy9GjHJBWj9oITzD2FmNV\n/yCGIeW3CClOyCtzJyNLhYf5Sr+XjoKRQVN/+7+C/l2YL6Sg4Ok/PRMm6iH+u2QB\nJTY1d0pOdfUPqR8gKsVJgBGE04iwE/RmLpp9/XZRAoGAFtaa9JeHk9dmZiST3lev\ns5syeOK1cCj1+nJer/GPEjqWMKxbCULvoEYBp7RaoEXjfGi7P4Mc6YHnbljHc+sL\niJzHhxrv/HYZdlCdTU3IRWT0sNHzqZemfYnsVTSp+4y61sGDxioDYL4CLnMq5T2F\nqzfc2qp3s8ApVloY3giuqnI=\n-----END PRIVATE KEY-----\n",
964
+ "client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
965
+ "client_id": "114883060650442183907",
966
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
967
+ "token_uri": "https://oauth2.googleapis.com/token",
968
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
969
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
970
+ "universe_domain": "googleapis.com"
971
+ }
972
+
973
+ insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)