Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,10 @@ import io
|
|
| 8 |
import base64
|
| 9 |
from google.cloud import bigquery
|
| 10 |
from google.oauth2 import service_account
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
## Single value - 268 --> 675
|
| 13 |
## Feature Specific - 676 --> 980
|
|
@@ -556,12 +560,84 @@ if bundle_by == "Feature specific":
|
|
| 556 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 557 |
|
| 558 |
|
| 559 |
-
col1, col2 = st.columns([0.16, 1])
|
| 560 |
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
"Business_Head": business_head,
|
| 566 |
"Company_ID": company_id,
|
| 567 |
"Company_Name": company_name,
|
|
@@ -575,7 +651,7 @@ if bundle_by == "Feature specific":
|
|
| 575 |
"Fee_Type": selected_fee_type,
|
| 576 |
"Variable_Type": selected_variable_type,
|
| 577 |
"Chargeable_on": selected_chargeable_on,
|
| 578 |
-
"Fee_Nature":
|
| 579 |
"Commercial_value": user_input_3,
|
| 580 |
"Fee_reversal": 0,
|
| 581 |
"Reversal_%": 0,
|
|
@@ -584,93 +660,24 @@ if bundle_by == "Feature specific":
|
|
| 584 |
"Threshold_option": threshold,
|
| 585 |
"Expected_Billing": expected_billing,
|
| 586 |
"Payment_Method": selected_payment_method,
|
| 587 |
-
"Plan_Validity": selected_plan_validity
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
global_user_data.append((user_name, user_data))
|
| 591 |
-
|
| 592 |
-
# Generate PM_id and add it to user_data
|
| 593 |
-
rule_id = generate_rule_id(user_data)
|
| 594 |
-
user_data['rule_id'] = rule_id
|
| 595 |
-
|
| 596 |
-
# Generate Plan ID and add it to user_data
|
| 597 |
-
plan_id = generate_plan_id(user_data)
|
| 598 |
-
user_data['plan_id'] = plan_id
|
| 599 |
-
|
| 600 |
-
save_user_data(user_data) # Save user data after submission
|
| 601 |
-
|
| 602 |
-
# Display saved records
|
| 603 |
-
display_saved_records()
|
| 604 |
-
|
| 605 |
-
with col2:
|
| 606 |
-
if st.button("Export data to BQ"):
|
| 607 |
-
from google.oauth2 import service_account
|
| 608 |
-
from google.cloud import bigquery
|
| 609 |
-
|
| 610 |
-
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 611 |
-
# Use from_service_account_info instead of from_service_account_file
|
| 612 |
-
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 613 |
-
|
| 614 |
-
# Initialize a BigQuery client
|
| 615 |
-
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 616 |
-
|
| 617 |
-
# Specify the table reference
|
| 618 |
-
table_ref = f"{project_id}.{dataset_id}.{table_id}"
|
| 619 |
-
table = client.get_table(table_ref)
|
| 620 |
-
|
| 621 |
-
# Insert form data into the table
|
| 622 |
-
rows_to_insert = [user_data]
|
| 623 |
-
errors = client.insert_rows_json(table, rows_to_insert)
|
| 624 |
-
|
| 625 |
-
if errors:
|
| 626 |
-
print(f"Errors occurred while inserting rows: {errors}")
|
| 627 |
-
else:
|
| 628 |
-
print("Insert successful")
|
| 629 |
-
|
| 630 |
-
project_id = "fynd-db"
|
| 631 |
-
dataset_id = "finance_dwh"
|
| 632 |
-
table_id = "plan_v2"
|
| 633 |
-
user_data = {
|
| 634 |
-
"Business_Head": business_head,
|
| 635 |
-
"Company_ID": company_id,
|
| 636 |
-
"Company_Name": company_name,
|
| 637 |
-
"Currency": currency,
|
| 638 |
-
"Bundle_by": bundle_by,
|
| 639 |
-
"Plan_Name": plan_name,
|
| 640 |
-
"Plan_Description": plan_description,
|
| 641 |
-
"Product_lines": ordering_channels,
|
| 642 |
-
"Fulfilling_Location": fulfilling_location,
|
| 643 |
-
"Application_ID": application_id,
|
| 644 |
-
"Fee_Type": selected_fee_type,
|
| 645 |
-
"Variable_Type": selected_variable_type,
|
| 646 |
-
"Chargeable_on": selected_chargeable_on,
|
| 647 |
-
"Fee_Nature": "Flat currency",
|
| 648 |
-
"Commercial_value": user_input_3,
|
| 649 |
-
"Fee_reversal": 0,
|
| 650 |
-
"Reversal_%": 0,
|
| 651 |
-
"Usage_limit": usage_3,
|
| 652 |
-
"Threshold_value": Capping_or_Minimum_Guarantee_3,
|
| 653 |
-
"Threshold_option": threshold,
|
| 654 |
-
"Expected_Billing": expected_billing,
|
| 655 |
-
"Payment_Method": selected_payment_method,
|
| 656 |
-
"Plan_Validity": selected_plan_validity
|
| 657 |
-
}
|
| 658 |
-
|
| 659 |
-
service_account_info = {
|
| 660 |
-
"type": "service_account",
|
| 661 |
-
"project_id": "fynd-db",
|
| 662 |
-
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 663 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2PQ4VBElLfCv4qbP9JGljvLsj5b\nC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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",
|
| 664 |
-
"client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
|
| 665 |
-
"client_id": "114883060650442183907",
|
| 666 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 667 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 668 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 669 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 670 |
-
"universe_domain": "googleapis.com"
|
| 671 |
-
}
|
| 672 |
|
| 673 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
|
| 675 |
|
| 676 |
###################################################### Single value ###########################################################
|
|
@@ -858,125 +865,128 @@ elif bundle_by == "Single value":
|
|
| 858 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 859 |
|
| 860 |
|
| 861 |
-
col1, col2 = st.columns([0.16, 1])
|
| 862 |
-
|
| 863 |
-
with col1:
|
| 864 |
# Submit button
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
|
| 894 |
-
|
| 895 |
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
|
| 904 |
|
| 905 |
-
|
| 906 |
|
| 907 |
-
|
| 908 |
-
|
|
|
|
| 909 |
|
| 910 |
-
|
| 911 |
-
|
|
|
|
| 912 |
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 917 |
# Use from_service_account_info instead of from_service_account_file
|
| 918 |
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 919 |
|
| 920 |
# Initialize a BigQuery client
|
| 921 |
client = bigquery.Client(credentials=credentials, project=project_id)
|
|
|
|
| 922 |
|
| 923 |
# Specify the table reference
|
| 924 |
table_ref = f"{project_id}.{dataset_id}.{table_id}"
|
| 925 |
table = client.get_table(table_ref)
|
|
|
|
| 926 |
|
| 927 |
# Insert form data into the table
|
| 928 |
rows_to_insert = [user_data]
|
| 929 |
errors = client.insert_rows_json(table, rows_to_insert)
|
| 930 |
|
| 931 |
if errors:
|
| 932 |
-
|
|
|
|
| 933 |
else:
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
|
|
|
|
|
|
|
|
|
| 980 |
|
|
|
|
| 981 |
|
| 982 |
-
insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
|
|
|
|
| 8 |
import base64
|
| 9 |
from google.cloud import bigquery
|
| 10 |
from google.oauth2 import service_account
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
logging.basicConfig(level=logging.INFO)
|
| 14 |
+
|
| 15 |
|
| 16 |
## Single value - 268 --> 675
|
| 17 |
## Feature Specific - 676 --> 980
|
|
|
|
| 560 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 561 |
|
| 562 |
|
|
|
|
| 563 |
|
| 564 |
+
if st.button("Submit", key ='submit_button'):
|
| 565 |
+
# Save user data
|
| 566 |
+
user_data = {
|
| 567 |
+
"Business_Head": business_head,
|
| 568 |
+
"Company_ID": company_id,
|
| 569 |
+
"Company_Name": company_name,
|
| 570 |
+
"Currency": currency,
|
| 571 |
+
"Bundle_by": bundle_by,
|
| 572 |
+
"Plan_Name": plan_name,
|
| 573 |
+
"Plan_Description": plan_description,
|
| 574 |
+
"Product_lines": ordering_channels,
|
| 575 |
+
"Fulfilling_Location": fulfilling_location,
|
| 576 |
+
"Application_ID": application_id,
|
| 577 |
+
"Fee_Type": selected_fee_type,
|
| 578 |
+
"Variable_Type": selected_variable_type,
|
| 579 |
+
"Chargeable_on": selected_chargeable_on,
|
| 580 |
+
"Fee_Nature": selected_fee_nature,
|
| 581 |
+
"Commercial_value": user_input_3,
|
| 582 |
+
"Fee_reversal": 0,
|
| 583 |
+
"Reversal_%": 0,
|
| 584 |
+
"Usage_limit": usage_3,
|
| 585 |
+
"Threshold_value": Capping_or_Minimum_Guarantee_3,
|
| 586 |
+
"Threshold_option": threshold,
|
| 587 |
+
"Expected_Billing": expected_billing,
|
| 588 |
+
"Payment_Method": selected_payment_method,
|
| 589 |
+
"Plan_Validity": selected_plan_validity,
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
global_user_data.append((user_name, user_data))
|
| 593 |
+
|
| 594 |
+
# Generate PM_id and add it to user_data
|
| 595 |
+
rule_id = generate_rule_id(user_data)
|
| 596 |
+
user_data['rule_id'] = rule_id
|
| 597 |
+
|
| 598 |
+
# Generate Plan ID and add it to user_data
|
| 599 |
+
plan_id = generate_plan_id(user_data)
|
| 600 |
+
user_data['plan_id'] = plan_id
|
| 601 |
+
|
| 602 |
+
save_user_data(user_data) # Save user data after submission
|
| 603 |
+
|
| 604 |
+
# Display saved records
|
| 605 |
+
display_saved_records()
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
if st.button("Export data to BQ"):
|
| 609 |
+
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 610 |
+
try:
|
| 611 |
+
# Use from_service_account_info instead of from_service_account_file
|
| 612 |
+
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 613 |
+
|
| 614 |
+
# Initialize a BigQuery client
|
| 615 |
+
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 616 |
+
logging.info("BigQuery client initialized successfully.")
|
| 617 |
+
|
| 618 |
+
# Specify the table reference
|
| 619 |
+
table_ref = f"{project_id}.{dataset_id}.{table_id}"
|
| 620 |
+
table = client.get_table(table_ref)
|
| 621 |
+
logging.info(f"Table reference obtained: {table_ref}")
|
| 622 |
+
|
| 623 |
+
# Insert form data into the table
|
| 624 |
+
rows_to_insert = [user_data]
|
| 625 |
+
errors = client.insert_rows_json(table, rows_to_insert)
|
| 626 |
+
|
| 627 |
+
if errors:
|
| 628 |
+
logging.error(f"Errors occurred while inserting rows: {errors}")
|
| 629 |
+
st.error(f"Errors occurred while inserting rows: {errors}")
|
| 630 |
+
else:
|
| 631 |
+
logging.info("Insert successful")
|
| 632 |
+
st.success("Insert successful")
|
| 633 |
+
except Exception as e:
|
| 634 |
+
logging.exception("An error occurred during the BigQuery insert operation.")
|
| 635 |
+
st.error(f"An error occurred: {e}")
|
| 636 |
+
|
| 637 |
+
project_id = "fynd-db"
|
| 638 |
+
dataset_id = "finance_dwh"
|
| 639 |
+
table_id = "plan_v2"
|
| 640 |
+
user_data = {
|
| 641 |
"Business_Head": business_head,
|
| 642 |
"Company_ID": company_id,
|
| 643 |
"Company_Name": company_name,
|
|
|
|
| 651 |
"Fee_Type": selected_fee_type,
|
| 652 |
"Variable_Type": selected_variable_type,
|
| 653 |
"Chargeable_on": selected_chargeable_on,
|
| 654 |
+
"Fee_Nature": "Flat currency",
|
| 655 |
"Commercial_value": user_input_3,
|
| 656 |
"Fee_reversal": 0,
|
| 657 |
"Reversal_%": 0,
|
|
|
|
| 660 |
"Threshold_option": threshold,
|
| 661 |
"Expected_Billing": expected_billing,
|
| 662 |
"Payment_Method": selected_payment_method,
|
| 663 |
+
"Plan_Validity": selected_plan_validity
|
| 664 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
|
| 666 |
+
service_account_info = {
|
| 667 |
+
"type": "service_account",
|
| 668 |
+
"project_id": "fynd-db",
|
| 669 |
+
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 670 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2PQ4VBElLfCv4qbP9JGljvLsj5b\nC9UWe9rWgRrw2Z88LlVmFy3k4Om80Q57gW3hSYZpG4rBhC9+YRXjZ+Iq5SFEJQ+U\nj8ej7q6DnI8Prbvw/e13JH1pxm9AUQDm+sTsBmvjh4Ye02vKbfUP+pFOM0eC3Eoa\nOyG7unZnDuAaK9g87xVjd9HtD6MfaM0EHAEF1eyC4UqeiXTbVMwi7+0IGA2evEDZ\n3WRR2i+lAgMBAAECggEAF7Vis7NVsVqFfCS/moFTAMLfWLF87r67EIK/DwSpHloZ\n5YJdsDz3ORKmZC98aRSthDfC9UUyt270dXItAj0jmTFgWB6HgE8OQ1zUbmo3MHG+\ntPwMWmqwY2gsBMV2Xefot1QJxYH+AYkrxeFv5NgC+FaPSiy8QSHZlQqcxYtlP8kY\nzv8QFMgZ3b0sixK+YcSjCRXHu/DznnS/ZU7XlTALxANa50hT11rVLq6zYDF40fqC\nOWCOZvupjMOnNimXCWn7q6D1F8S/IMYlnHArJpEb7SdbJnJzxU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| 673 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 674 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 675 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 676 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 677 |
+
"universe_domain": "googleapis.com"
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
|
| 681 |
|
| 682 |
|
| 683 |
###################################################### Single value ###########################################################
|
|
|
|
| 865 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 866 |
|
| 867 |
|
|
|
|
|
|
|
|
|
|
| 868 |
# Submit button
|
| 869 |
+
if st.button("Submit"):
|
| 870 |
+
# Save user data
|
| 871 |
+
user_data = {
|
| 872 |
+
"Business Head": business_head,
|
| 873 |
+
"Company ID": company_id,
|
| 874 |
+
"Company Name": company_name,
|
| 875 |
+
"Currency": currency,
|
| 876 |
+
"Bundle by": bundle_by,
|
| 877 |
+
"Plan Name": plan_name,
|
| 878 |
+
"Plan Description": plan_description,
|
| 879 |
+
"Product lines": ordering_channels,
|
| 880 |
+
"Fulfilling Location": fulfilling_location,
|
| 881 |
+
"Application ID": application_id,
|
| 882 |
+
"Fee Type": selected_fee_type,
|
| 883 |
+
"Variable Type": selected_variable_type,
|
| 884 |
+
"Chargeable on": selected_chargeable_on,
|
| 885 |
+
"Fee Nature": "Flat currency",
|
| 886 |
+
"Commercial value": user_input_3,
|
| 887 |
+
"Fee reversal": 0,
|
| 888 |
+
"Reversal %": 0,
|
| 889 |
+
"Usage limit": usage_3,
|
| 890 |
+
"Threshold value": 0,
|
| 891 |
+
"Threshold option": 0,
|
| 892 |
+
"Expected Billing": user_input_3,
|
| 893 |
+
"Plan Validity": selected_plan_validity,
|
| 894 |
+
"Payment Method": selected_payment_method,
|
| 895 |
+
|
| 896 |
+
}
|
| 897 |
|
| 898 |
+
global_user_data.append((user_name, user_data))
|
| 899 |
|
| 900 |
+
# Generate PM_id and add it to user_data
|
| 901 |
+
rule_id = generate_rule_id(user_data)
|
| 902 |
+
user_data['rule_id'] = rule_id
|
| 903 |
|
| 904 |
+
# Generate Plan ID and add it to user_data
|
| 905 |
+
plan_id = generate_plan_id(user_data)
|
| 906 |
+
user_data['plan_id'] = plan_id
|
| 907 |
|
| 908 |
|
| 909 |
+
save_user_data(user_data) # Save user data after submission
|
| 910 |
|
| 911 |
+
# Display saved records
|
| 912 |
+
display_saved_records()
|
| 913 |
+
if st.button("Export data to BQ"):
|
| 914 |
|
| 915 |
+
import logging
|
| 916 |
+
from google.oauth2 import service_account
|
| 917 |
+
from google.cloud import bigquery
|
| 918 |
|
| 919 |
+
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 920 |
+
try:
|
|
|
|
|
|
|
| 921 |
# Use from_service_account_info instead of from_service_account_file
|
| 922 |
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 923 |
|
| 924 |
# Initialize a BigQuery client
|
| 925 |
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 926 |
+
logging.info("BigQuery client initialized successfully.")
|
| 927 |
|
| 928 |
# Specify the table reference
|
| 929 |
table_ref = f"{project_id}.{dataset_id}.{table_id}"
|
| 930 |
table = client.get_table(table_ref)
|
| 931 |
+
logging.info(f"Table reference obtained: {table_ref}")
|
| 932 |
|
| 933 |
# Insert form data into the table
|
| 934 |
rows_to_insert = [user_data]
|
| 935 |
errors = client.insert_rows_json(table, rows_to_insert)
|
| 936 |
|
| 937 |
if errors:
|
| 938 |
+
logging.error(f"Errors occurred while inserting rows: {errors}")
|
| 939 |
+
st.error(f"Errors occurred while inserting rows: {errors}")
|
| 940 |
else:
|
| 941 |
+
logging.info("Insert successful")
|
| 942 |
+
st.success("Insert successful")
|
| 943 |
+
except Exception as e:
|
| 944 |
+
logging.exception("An error occurred during the BigQuery insert operation.")
|
| 945 |
+
st.error(f"An error occurred: {e}")
|
| 946 |
+
|
| 947 |
+
# Your data and service account info here
|
| 948 |
+
project_id = "fynd-db"
|
| 949 |
+
dataset_id = "finance_dwh"
|
| 950 |
+
table_id = "plan_v2"
|
| 951 |
+
user_data = {
|
| 952 |
+
"Business_Head": business_head,
|
| 953 |
+
"Company_ID": company_id,
|
| 954 |
+
"Company_Name": company_name,
|
| 955 |
+
"Currency": currency,
|
| 956 |
+
"Bundle_by": bundle_by,
|
| 957 |
+
"Plan_Name": plan_name,
|
| 958 |
+
"Plan_Description": plan_description,
|
| 959 |
+
"Product_lines": ordering_channels,
|
| 960 |
+
"Fulfilling_Location": fulfilling_location,
|
| 961 |
+
"Application_ID": application_id,
|
| 962 |
+
"Fee_Type": selected_fee_type,
|
| 963 |
+
"Variable_Type": selected_variable_type,
|
| 964 |
+
"Chargeable_on": selected_chargeable_on,
|
| 965 |
+
"Fee_Nature": "Flat currency",
|
| 966 |
+
"Commercial_value": user_input_3,
|
| 967 |
+
"Fee_reversal": 0,
|
| 968 |
+
"Reversal_%": 0,
|
| 969 |
+
"Usage_limit": usage_3,
|
| 970 |
+
"Threshold_value": 0,
|
| 971 |
+
"Threshold_option": 0,
|
| 972 |
+
"Expected_Billing": user_input_3,
|
| 973 |
+
"Payment_Method": selected_payment_method,
|
| 974 |
+
"Plan_Validity": selected_plan_validity
|
| 975 |
+
}
|
| 976 |
+
|
| 977 |
+
service_account_info = {
|
| 978 |
+
"type": "service_account",
|
| 979 |
+
"project_id": "fynd-db",
|
| 980 |
+
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 981 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2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P/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",
|
| 982 |
+
"client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
|
| 983 |
+
"client_id": "114883060650442183907",
|
| 984 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 985 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 986 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 987 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 988 |
+
"universe_domain": "googleapis.com"
|
| 989 |
+
}
|
| 990 |
|
| 991 |
+
insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
|
| 992 |
|
|
|