Spaces:
Runtime error
Runtime error
File size: 1,988 Bytes
53da065 d8d92bc 53da065 d8d92bc 53da065 46e9dd5 53da065 d8d92bc 53da065 d8d92bc 53da065 d8d92bc 3668019 |
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 |
import requests
import streamlit as st
import sqlite3
import pandas as pd
st.set_page_config('Price',menu_items={'About': "This is an *extremely* cool app!"})
con = sqlite3.connect("mydb.db")
cur = con.cursor()
menu=['Find price']
ch=st.sidebar.selectbox('Menu',menu)
if 'Find price' in ch:
with st.container():
st.title('Search for price')
ti=st.text_input('Search')
if len(ti)>0:
r=requests.get('https://www.pricerunner.dk/public/search/v3/dk?q='+ti)
x=r.json()
for i in x['products']:
with st.container():
lc , rc = st.columns(2)
with lc:
add='https:/www.pricerunner.dk'+i['image']['path']
st.image(add)
with rc:
id=i['id']
comp=i['url']
des=i['description']
low=i['lowestPrice']['amount']
name=i['name']
r2=requests.get('https://www.pricerunner.dk/public/productlistings/v3/pl/2-'+id+'/dk/filter')
x2=r2.json()
x3=x2['filteredOfferList']['merchantOffers'][0]['offers'][0]['url']
link=('https://www.pricerunner.dk'+ x3)
st.header(name)
st.write(des)
st.success(low+' DKK')
st.write('Link to buy:')
st.write('https://www.pricerunner.dk'+ x3)
cur.execute("insert into proucts values(?,?,?,?)", (name,low,des,link))
con.commit()
st.write('---')
df = pd.read_sql('SELECT * FROM proucts ', con)
h = df.to_csv(sep=',')
c = st.download_button("Download csv file",h,'price.csv','text/csv',)
if c :
cur.execute("DELETE from proucts ")
con.commit()
st.warning('Database is empty now again,try with new search again')
con.close() |