File size: 1,892 Bytes
b01efe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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