Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
def get_auto_lot_info(query):
|
7 |
+
url = "https://ru.autoauctionspot.com/salvage-cars-auction/"
|
8 |
+
payload = {
|
9 |
+
'lot-type-available-to-bid': '1',
|
10 |
+
'search-term': query,
|
11 |
+
}
|
12 |
+
|
13 |
+
try:
|
14 |
+
response = requests.post(url, data=payload)
|
15 |
+
response.raise_for_status()
|
16 |
+
|
17 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
18 |
+
lot_title = soup.find('h1', class_='slider-name').text.strip()
|
19 |
+
damage_info = soup.find('div', class_='char-line')
|
20 |
+
damage_type_primary = damage_info.find('span', class_='char-info-envelope').text.strip()
|
21 |
+
damage_type_secondary = damage_info.find_all('span', class_='char-info-envelope')[1].text.strip()
|
22 |
+
|
23 |
+
lot_info = f"Лот: {lot_title}\nУщерб: {damage_type_primary}, {damage_type_secondary}\n"
|
24 |
+
|
25 |
+
char_wrap = soup.find_all('div', class_='char-wrap')
|
26 |
+
for char_box in char_wrap:
|
27 |
+
char_lines = char_box.find_all('div', class_='char-line')
|
28 |
+
for char_line in char_lines:
|
29 |
+
char_name = char_line.find('span', class_='char-name').text.strip()
|
30 |
+
char_info = char_line.find('span', class_='char-info').text.strip()
|
31 |
+
lot_info += f"{char_name}: {char_info}\n"
|
32 |
+
|
33 |
+
car_slider = soup.find('div', class_='car-slider')
|
34 |
+
image_links = [figure.a['href'] for figure in car_slider.find_all('figure')]
|
35 |
+
|
36 |
+
images = []
|
37 |
+
for link in image_links:
|
38 |
+
image_response = requests.get(link)
|
39 |
+
image_data = BytesIO(image_response.content)
|
40 |
+
images.append(image_data)
|
41 |
+
|
42 |
+
final_bid_info = soup.find('div', class_='copart-bid_final')
|
43 |
+
final_bid_title = final_bid_info.find('span', class_='copart-bid-title').text.strip()
|
44 |
+
final_bid_amount = final_bid_info.find('span', class_='copart-price').text.strip()
|
45 |
+
final_bid_info = f"{final_bid_title}: {final_bid_amount}"
|
46 |
+
|
47 |
+
return lot_info, images, final_bid_info
|
48 |
+
|
49 |
+
except requests.RequestException as e:
|
50 |
+
print(f"Ошибка при запросе {url}: {e}")
|
51 |
+
return None, None, None
|
52 |
+
except Exception as e:
|
53 |
+
print(f"Необработанная ошибка в get_auto_lot_info: {e}")
|
54 |
+
return None, None, None
|
55 |
+
|
56 |
+
def main():
|
57 |
+
# Добавляем кликабельную надпись AlfaCross сверху
|
58 |
+
st.markdown("[AlfaCross](https://t.me/alfacross_bot)")
|
59 |
+
|
60 |
+
st.title("Auto Lot Info Web App")
|
61 |
+
query = st.text_input("Введите запрос для поиска лота:")
|
62 |
+
|
63 |
+
if st.button("Получить информацию о лоте"):
|
64 |
+
lot_info, images, final_bid_info = get_auto_lot_info(query)
|
65 |
+
|
66 |
+
if lot_info and images and final_bid_info:
|
67 |
+
st.markdown(lot_info)
|
68 |
+
|
69 |
+
for image in images:
|
70 |
+
st.image(image)
|
71 |
+
|
72 |
+
st.markdown(final_bid_info)
|
73 |
+
else:
|
74 |
+
st.markdown("Информация о лоте не найдена.")
|
75 |
+
|
76 |
+
# Добавляем надпись Starchik снизу
|
77 |
+
st.markdown("[Starchik](https://t.me/Starchik_1)")
|
78 |
+
|
79 |
+
# Добавим обработку GET-запросов
|
80 |
+
if "query" in st.query_params:
|
81 |
+
query = st.query_params["query"]
|
82 |
+
lot_info, images, final_bid_info = get_auto_lot_info(query)
|
83 |
+
if lot_info and images and final_bid_info:
|
84 |
+
st.markdown(lot_info)
|
85 |
+
for image in images:
|
86 |
+
st.image(image)
|
87 |
+
st.markdown(final_bid_info)
|
88 |
+
else:
|
89 |
+
main()
|