sanjeev21's picture
Update clickcounter.py
b01efe7
Raw
History Blame Contribute Delete
1.89 kB
import streamlit as st
from st_click_detector import click_detector
def clickcounter(img_list, sku_list, price_list, disc_list, org_price, url_list, product_list):
print('First row in Click Counter:',img_list[0], sku_list[0], price_list[0] )
content = "<table> <tr> "
if len(sku_list) > 5:
range_var = 5
else:
range_var = len(sku_list)
# To ensure clicked_sku is not empty string creating a while loop
for idx in range(range_var):
str1 = "<td > " \
"<p> <div><a href='{}' target='_blank' id={}><img width='200' height='200' src={}></a> <br>" \
"<b>{} </b> <br>" \
"<b>S.K.U:</b> {} <br>" \
"<b>S.P:</b> ${} <br>" \
"<b>Discount:</b> %{} <br>" \
"<b>L.P:</b> ${} </p> " \
"</td>".format(url_list[idx], sku_list[idx], img_list[idx], product_list[idx], sku_list[idx], price_list[idx], disc_list[idx],
org_price[idx])
#print('Content # {}, ID: {}, Type of ID: {}'.format(idx+1,sku_list[idx], type(sku_list[idx])))
content += str1
content += ' </tr> </table>'
clicked_sku = click_detector(content)
print("This SKU has been Clicked right Now: {}; Type of the variable is {}; Length of String: {}".format(clicked_sku, type(clicked_sku), len(clicked_sku)))
if clicked_sku not in st.session_state:
print("The Clicked SKU: {} is new. Storing it in Session State and Initializing it's value to Zero".format(clicked_sku))
st.session_state[clicked_sku] = 0
if clicked_sku:
print("Updating the Click count of the Clicked SKU: {} by 1".format(clicked_sku))
st.session_state[clicked_sku] += 1
print("The Session State of the Clicked SKU: {} = {}".format(clicked_sku, st.session_state[clicked_sku]))
return clicked_sku, st.session_state