forked from rliu9/cheapBuy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cheapBuy_user_interface.py
187 lines (157 loc) · 6.5 KB
/
cheapBuy_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"""
Copyright (c) 2021 Anshul Patel
This code is licensed under MIT license (see LICENSE.MD for details)
@author: cheapBuy
"""
# Import Libraries
import webbrowser
import pandas as pd
from source.web_scrappers.WebScrapper import WebScrapper
import os
import streamlit as st
import sys
sys.path.append('../')
title = '<p style="font-family:Bradley Hand, cursive; color:#64b3f4; font-size: 157px;">cheapBuy</p>'
# st.title("CheapBuy")
st.markdown(title, unsafe_allow_html=True)
# st.image("media/saveMoney2.gif")
url_sidebar = st.sidebar.text_input('Quick Action: Open a new page')
# st.sidebar.image("media/cheapBuy_Banner.gif")
st.sidebar.image("media/saveMoney2.gif")
st.sidebar.title("Customize Options Here:")
sites = st.sidebar.selectbox("Select the website:", ("All Sites",
"amazon", "walmart", "ebay", "bjs", "costco", "bestbuy", "traderjoes", "kroger"))
price_range = st.sidebar.selectbox("Select the price range:", (
"all", "Under $50", "[$50, $100)", "[$100, $150)", "[$150, $200)", "$200 & Above"))
st.header("Website: " + sites.capitalize() +
'| |' + "Price Range: " + price_range)
#st.header("Price Range: " + price_range)
if url_sidebar:
webbrowser.open(url_sidebar)
# Hide Footer in Streamlit
hide_menu_style = """
<style>
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_menu_style, unsafe_allow_html=True)
# Display Image
st.sidebar.write("cheapBuy provides you ease to buy any product through your favourite website's like Amazon, Walmart, Ebay, Bjs, Costco, etc, by providing prices of the same product from all different websites")
#st.write("cheapBuy provides you ease to buy any product through your favourite website's like Amazon, Walmart, Ebay, Bjs, Costco, etc, by providing prices of the same product from all different websites")
url = st.text_input('Enter the product website link')
def price_filter(price_range):
#price_min, price_max = 0.0, 0.0
if price_range == "Under $50":
price_min, price_max = 0.0, 49.99
elif price_range == "[$50, $100)":
price_min, price_max = 50.0, 99.99
elif price_range == "[$100, $150)":
price_min, price_max = 100.0, 149.99
elif price_range == "[$150, $200)":
price_min, price_max = 150.0, 199.99
elif price_range == "$200 & Above":
price_min, price_max = 200.0, float('inf')
else:
price_min, price_max = 0.0, float('inf')
return price_min, price_max
price_min, price_max = price_filter(price_range)
# Pass url to method
if url:
webScrapper = WebScrapper(url)
results = webScrapper.call_scrapper()
# Use st.columns based on return values
description, url, price, site = [], [], [], []
if sites == "All Sites":
for result in results:
# add results that only fit to selected price range :
if result:
try:
if price_min <= float(result['price'][1:]) <= price_max:
description.append(result['description'])
url.append(result['url'])
price.append(
float(result['price'].strip('$').rstrip('0')))
site.append(result['site'])
except Exception as e:
print(e)
else:
# if sites not in site:
#st.error('Sorry, there is no same product in your selected website.')
# else:
for result in results:
# add results that only fit to selected price range :
if result:
try:
if price_min <= float(result['price'][1:]) <= price_max:
# print(result['site'])
if result['site'].strip() == sites:
description.append(result['description'])
url.append(result['url'])
price.append(
float(result['price'].strip('$').rstrip('0')))
site.append(result['site'])
except Exception as e:
print(e)
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}, index=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)
for s, u, p in zip(site, url, price):
if p == min(price):
if st.button('👉'+s+'👈'):
webbrowser.open(u)
else:
if st.button(s):
webbrowser.open(u)
elif not description or not url or not price or not site:
st.error('Sorry, there is no product on your selected options.')
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: #FBD786;
color: black;
text-align: center;
}
</style>
<div class="footer">
<p><a style='display: block; text-align: center;' href="https://github.com/freakleesin/cheapBuy" target="_blank">Developed with ❤ by cheapBuy</a></p>
<p><a style='display: block; text-align: center;' href="https://github.com/freakleesin/cheapBuy/blob/main/LICENSE" target="_blank">MIT License Copyright (c) 2021 cheapBuy</a></p>
<p>Contributors:
<a href="https://github.com/Mahaoqu" target="_blank">Haoqu</a>,
<a href="https://github.com/joshlin5" target="_blank">Joshua</a>,
<a href="https://github.com/zhijin44" target="_blank">Zhijin</a>,
<a href="https://github.com/SamuelVivivi" target="_blank">Guanyu</a>,
<a href="https://github.com/freakleesin" target="_blank">Rundi</a>
</div>
"""
st.markdown(footer, unsafe_allow_html=True)