sanjeev21 commited on
Commit
b01efe7
·
1 Parent(s): 19d0617

Update clickcounter.py

Browse files
Files changed (1) hide show
  1. clickcounter.py +41 -0
clickcounter.py CHANGED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from st_click_detector import click_detector
3
+
4
+
5
+ def clickcounter(img_list, sku_list, price_list, disc_list, org_price, url_list, product_list):
6
+ print('First row in Click Counter:',img_list[0], sku_list[0], price_list[0] )
7
+ content = "<table> <tr> "
8
+ if len(sku_list) > 5:
9
+ range_var = 5
10
+ else:
11
+ range_var = len(sku_list)
12
+
13
+ # To ensure clicked_sku is not empty string creating a while loop
14
+
15
+ for idx in range(range_var):
16
+ str1 = "<td > " \
17
+ "<p> <div><a href='{}' target='_blank' id={}><img width='200' height='200' src={}></a> <br>" \
18
+ "<b>{} </b> <br>" \
19
+ "<b>S.K.U:</b> {} <br>" \
20
+ "<b>S.P:</b> ${} <br>" \
21
+ "<b>Discount:</b> %{} <br>" \
22
+ "<b>L.P:</b> ${} </p> " \
23
+ "</td>".format(url_list[idx], sku_list[idx], img_list[idx], product_list[idx], sku_list[idx], price_list[idx], disc_list[idx],
24
+ org_price[idx])
25
+ #print('Content # {}, ID: {}, Type of ID: {}'.format(idx+1,sku_list[idx], type(sku_list[idx])))
26
+ content += str1
27
+ content += ' </tr> </table>'
28
+
29
+ clicked_sku = click_detector(content)
30
+ 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)))
31
+
32
+
33
+ if clicked_sku not in st.session_state:
34
+ print("The Clicked SKU: {} is new. Storing it in Session State and Initializing it's value to Zero".format(clicked_sku))
35
+ st.session_state[clicked_sku] = 0
36
+
37
+ if clicked_sku:
38
+ print("Updating the Click count of the Clicked SKU: {} by 1".format(clicked_sku))
39
+ st.session_state[clicked_sku] += 1
40
+ print("The Session State of the Clicked SKU: {} = {}".format(clicked_sku, st.session_state[clicked_sku]))
41
+ return clicked_sku, st.session_state