-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslash_user_interface.py
117 lines (97 loc) · 3.48 KB
/
slash_user_interface.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
Copyright (c) 2021 Anshul Patel
This code is licensed under MIT license (see LICENSE.MD for details)
@author: slash
"""
# Import Libraries
import sys
sys.path.append('../')
import streamlit as st
from src.main_streamlit import search_items_API
import pandas as pd
from link_button import link_button
# Hide Footer in Streamlit
hide_menu_style = """
<style>
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_menu_style, unsafe_allow_html=True)
# Display Image
st.image("assets/slash.png")
st.write("Slash is a command line tool that scrapes the most popular e-commerce websites to get the best deals on the searched items across multiple websites")
product = st.text_input('Enter the product item name')
website = st.selectbox('Select the website',('Amazon', 'Walmart', 'Ebay', 'BestBuy', 'Target', 'Costco', 'All'))
website_dict = {
'Amazon':'az',
'Walmart':'wm',
'Ebay':'eb',
'BestBuy':'bb',
'Target':'tg',
'Costco':'cc',
'All':'all'
}
# Pass product and website to method
if st.button('Search') and product and website:
results = search_items_API(website_dict[website], product)
# Use st.columns based on return values
description = []
url = []
price = []
site = []
for result in results:
if result!={}:
description.append(result['title'])
url.append(result['link'])
price.append(float(''.join(result['price'].strip('$').rstrip('0').split(','))))
site.append(result['website'])
if len(price):
def highlight_row(dataframe):
#copy df to new - original data are not changed
df = dataframe.copy()
minimumPrice = df['Price'].min()
#set by condition
mask = df['Price'] == minimumPrice
df.loc[mask, :] = 'background-color: lightgreen'
df.loc[~mask,:] = 'background-color: ""'
return df
dataframe = pd.DataFrame({'Description': description, 'Price':price, 'Link':url, 'Website':site})
st.balloons()
st.markdown("<h1 style='text-align: center; color: #1DC5A9;'>RESULT</h1>", unsafe_allow_html=True)
st.dataframe(dataframe.style.apply(highlight_row, axis=None))
st.markdown("<h1 style='text-align: center; color: #1DC5A9;'>Visit the Website</h1>", unsafe_allow_html=True)
min_value = min(price)
min_idx = [i for i, x in enumerate(price) if x == min_value]
for minimum_i in min_idx:
link_button(site[minimum_i], url[minimum_i])
else:
st.error('Sorry!, there is no other website with same product')
# Add footer to UI
footer="""<style>
a:link , a:visited{
color: blue;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color: red;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: fixed;
left: 0;
bottom: 0%;
width: 100%;
background-color: #DFFFFA;
color: black;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with ❤ by <a style='display: block; text-align: center;' href="https://github.com/anshulp2912/slash" target="_blank">slash</a></p>
<p><a style='display: block; text-align: center;' href="https://github.com/anshulp2912/slash/blob/main/LICENSE" target="_blank">MIT License Copyright (c) 2021 Rohan Shah</a></p>
<p>Contributors: Anshul, Bhavya, Darshan, Pragna, Rohan</p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)