forked from rliu9/cheapBuy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheapBuy_user_interface1.py
151 lines (124 loc) · 4.91 KB
/
cheapBuy_user_interface1.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
"""
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:Apple Chancery, cursive; color:#2F184B; font-size: 157px;">CheapBuy</p>'
title = '<p style="font-family:Apple Chancery, cursive; color:#6B9080; font-size: 157px;">CheapBuy</p>'
st.markdown(title, unsafe_allow_html=True)
# Add tagline just below the title and to the right
tagline = '<p style="color: #6B9080; font-size: 24px; text-align: right;">Your One-Stop Shop for the Best Deals</p>'
st.markdown(tagline, unsafe_allow_html=True)
sites = st.selectbox("Select the website:", ("All Sites",
"amazon", "walmart", "ebay", "bjs", "costco", "bestbuy", "traderjoes", "kroger"))
st.header("Website: " + sites.capitalize() )
# Hide Footer in Streamlit
hide_menu_style = """
<style>
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_menu_style, unsafe_allow_html=True)
url = st.text_input('Enter the product')
# Pass url to method
if url:
webScrapper = WebScrapper(url)
results = webScrapper.call_scrapper(sites)
# 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:
for result in results:
# add results that only fit to selected price range :
if result:
try:
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: #F6FFF8'
df.loc[~mask, :] = 'background-color: #CCE3DE'
return df
dataframe = pd.DataFrame(
{'Description': description, 'Price': price, 'Link': url}, index=site)
st.snow()
st.markdown(
"<h1 style='text-align: center; color: #F6FFF8;'>RESULT</h1>", unsafe_allow_html=True)
st.dataframe(dataframe.style.apply(highlight_row, axis=None))
st.markdown(
"<h1 style='text-align: center; color: #F6FFF8;'>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: #6B9080;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color: #F6FFF8;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: fixed;
left: 0;
bottom: 0%;
width: 100%;
background-color: #CCE3DE;
color: black;
text-align: center;
}
</style>
<div class="footer">
<p><a style='display: block; text-align: center;' href="https://github.com/EZ7051/cheapBuy" target="_blank">Developed with ❤ by CheapBuy</a></p>
<p><a style='display: block; text-align: center;' href="https://github.com/EZ7051/cheapBuy/blob/main/LICENSE" target="_blank">MIT License Copyright (c) 2021 cheapBuy</a></p>
<p>Contributors:
<a href="https://github.com/EZ7051" target="_blank">Ejaz</a>,
<a href="https://github.com/shyni0201" target="_blank">Shynitha</a>,
<a href="https://github.com/sumalatha-99" target="_blank">Sumalatha</a>,
<a href="https://github.com/soubhagya31" target="_blank">Soubhagya</a>
</div>
"""
st.markdown(footer, unsafe_allow_html=True)