forked from anshulp2912/cheapBuy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheapBuy_user_interface.py
110 lines (89 loc) · 3.21 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
"""
Copyright (c) 2021 Anshul Patel
This code is licensed under MIT license (see LICENSE.MD for details)
@author: cheapBuy
"""
# Import Libraries
import sys
sys.path.append('../')
import streamlit as st
import os
from source.web_scrappers.WebScrapper import WebScrapper
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("media/cheapBuy_Banner.gif")
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')
# Pass url to method
if url:
webScrapper = WebScrapper(url)
results = webScrapper.call_scrapper()
# Use st.columns based on return values
description = []
url = []
price = []
site = []
for result in results:
if result!={}:
description.append(result['description'])
url.append(result['url'])
price.append(float(result['price'].strip('$').rstrip('0')))
site.append(result['site'])
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)
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/cheapBuy" target="_blank">cheapBuy</a></p>
<p><a style='display: block; text-align: center;' href="https://github.com/anshulp2912/cheapBuy/blob/main/LICENSE" target="_blank">MIT License Copyright (c) 2021 Anshul Patel</a></p>
<p>Contributors: Anshul, Bhavya, Darshan, Pragna, Rohan</p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)