|
from google.cloud import bigquery |
|
import functions_framework |
|
from query_seller_sale import queries |
|
from google.oauth2 import service_account |
|
import json |
|
import requests |
|
import streamlit as st |
|
import pyperclip |
|
from ap import send_message_via_webhook, Webhook_urls |
|
import pandas as pd |
|
import io |
|
import time |
|
|
|
|
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
.progress-bar { |
|
height: 20px; /* Adjusted thickness */ |
|
width: 100%; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
border-radius: 12px; |
|
position: relative; |
|
overflow: hidden; |
|
} |
|
.progress-bar span { |
|
display: block; |
|
height: 100%; |
|
width: 0%; |
|
background: linear-gradient(to right, #ff0000, #ff4d4d); /* Red gradient */ |
|
transition: width 0.3s ease; |
|
} |
|
</style> |
|
</head> |
|
</html> |
|
""" |
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
|
|
|
|
def check_duplicates(credentials_file): |
|
"""Check for duplicates using BigQuery with the provided credentials file.""" |
|
results = {} |
|
credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file)) |
|
client = bigquery.Client(credentials=credentials, project=credentials.project_id) |
|
|
|
query = queries["query"] |
|
|
|
|
|
with st.spinner(":red[Performing seller sale validation...]"): |
|
|
|
progress_bar = st.empty() |
|
progress_bar.markdown( |
|
""" |
|
<div class="progress-bar"> |
|
<span id="progress"></span> |
|
</div> |
|
""", unsafe_allow_html=True |
|
) |
|
|
|
try: |
|
query_job = client.query(query) |
|
|
|
for percent_complete in range(0, 101, 10): |
|
time.sleep(0.1) |
|
progress_bar.markdown( |
|
f""" |
|
<div class="progress-bar"> |
|
<span style="width: {percent_complete}%;"></span> |
|
</div> |
|
""", unsafe_allow_html=True |
|
) |
|
df = query_job.result().to_dataframe() |
|
st.write("", df) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
return results |
|
|
|
if not df.empty: |
|
results["Query Result"] = df |
|
|
|
return results |
|
|
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Upload service a/c credentials</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
|
|
|
|
credentials_file = st.file_uploader("", type="json") |
|
|
|
if credentials_file is not None: |
|
|
|
credentials_data = credentials_file.read().decode("utf-8") |
|
|
|
|
|
results = check_duplicates(credentials_data) |
|
|
|
if "Query Result" in results: |
|
df = results["Query Result"] |
|
|
|
|
|
csv = df.to_csv(index=False) |
|
excel = io.BytesIO() |
|
with pd.ExcelWriter(excel, engine='openpyxl') as writer: |
|
df.to_excel(writer, index=False) |
|
excel.seek(0) |
|
|
|
col1, col2 = st.columns([0.125, 0.5]) |
|
with col1: |
|
st.download_button( |
|
label=":red[Download CSV]", |
|
data=csv, |
|
file_name="seller_sale_recon.csv", |
|
mime="text/csv" |
|
) |
|
|
|
with col2: |
|
st.download_button( |
|
label=":red[Download Excel]", |
|
data=excel, |
|
file_name="seller_sale_recon.xlsx", |
|
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
|
) |
|
|