nick5363 commited on
Commit
2cdf938
·
verified ·
1 Parent(s): 470b856

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +24 -0
  2. app.py +33 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Base image
3
+ FROM python:3.10-slim
4
+
5
+ # System dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ wget curl gnupg unzip fonts-liberation libnss3 libatk1.0-0 \
8
+ libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 \
9
+ libxdamage1 libxrandr2 libgbm1 libasound2 libpangocairo-1.0-0 \
10
+ libgtk-3-0 libx11-xcb1 xvfb && \
11
+ apt-get clean && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Install Python dependencies
14
+ RUN pip install --no-cache-dir streamlit pandas playwright beautifulsoup4
15
+
16
+ # Install browser for Playwright
17
+ RUN playwright install --with-deps chromium
18
+
19
+ # Copy application code
20
+ COPY . /app
21
+ WORKDIR /app
22
+
23
+ # Run the app
24
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ from playwright.sync_api import sync_playwright
4
+ import pandas as pd
5
+
6
+ st.set_page_config(page_title="UOA Barchart", layout="wide")
7
+ st.title("Scrape Unusual Options Activity from Barchart")
8
+
9
+ @st.cache_data
10
+ def fetch_uoa():
11
+ with sync_playwright() as p:
12
+ browser = p.chromium.launch(headless=True)
13
+ page = browser.new_page()
14
+ page.goto("https://www.barchart.com/options/unusual-activity/stocks", timeout=60000)
15
+ page.wait_for_selector("table")
16
+ html = page.content()
17
+ browser.close()
18
+ return html
19
+
20
+ try:
21
+ from bs4 import BeautifulSoup
22
+ soup = BeautifulSoup(fetch_uoa(), "html.parser")
23
+ table = soup.find("table")
24
+ rows = table.find_all("tr")
25
+ data = []
26
+ for row in rows[1:]:
27
+ cols = [col.text.strip() for col in row.find_all("td")]
28
+ if cols:
29
+ data.append(cols)
30
+ df = pd.DataFrame(data)
31
+ st.dataframe(df)
32
+ except Exception as e:
33
+ st.error(f"Lỗi: {e}")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ streamlit
3
+ pandas
4
+ playwright
5
+ beautifulsoup4