testing
Browse files
app.py
CHANGED
|
@@ -102,6 +102,46 @@ def scrape_dividend_data(url):
|
|
| 102 |
|
| 103 |
return dividend_data
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
@app.get("/hello")
|
| 106 |
def greet_json():
|
| 107 |
return {"Hello": "World!"}
|
|
@@ -109,7 +149,7 @@ def greet_json():
|
|
| 109 |
|
| 110 |
@app.get("/dividend_history")
|
| 111 |
def get_dividend():
|
| 112 |
-
return
|
| 113 |
|
| 114 |
|
| 115 |
|
|
|
|
| 102 |
|
| 103 |
return dividend_data
|
| 104 |
|
| 105 |
+
def simple_dividend_extraction():
|
| 106 |
+
"""
|
| 107 |
+
Simple function to extract dividend data
|
| 108 |
+
"""
|
| 109 |
+
r = requests.get('https://scstrade.com/MarketStatistics/MS_xDates.aspx')
|
| 110 |
+
print("request done")
|
| 111 |
+
|
| 112 |
+
soup = BeautifulSoup(r.text, 'html.parser')
|
| 113 |
+
table = soup.find('table', {'id': 'list'})
|
| 114 |
+
|
| 115 |
+
results = []
|
| 116 |
+
|
| 117 |
+
if table:
|
| 118 |
+
print("in table")
|
| 119 |
+
rows = table.find_all('tr')[1:] # Skip header row
|
| 120 |
+
|
| 121 |
+
for row in rows:
|
| 122 |
+
print("in row")
|
| 123 |
+
cells = row.find_all('td')
|
| 124 |
+
|
| 125 |
+
if len(cells) >= 6:
|
| 126 |
+
company_name = cells[1].get_text(strip=True)
|
| 127 |
+
dividend_amount = cells[2].get_text(strip=True) or "No dividend"
|
| 128 |
+
dividend_date = cells[5].get_text(strip=True) or "No date"
|
| 129 |
+
print("adding data")
|
| 130 |
+
|
| 131 |
+
results.append({
|
| 132 |
+
'Company': company_name,
|
| 133 |
+
'Dividend': dividend_amount,
|
| 134 |
+
'Date': dividend_date
|
| 135 |
+
})
|
| 136 |
+
print(results)
|
| 137 |
+
|
| 138 |
+
return results
|
| 139 |
+
|
| 140 |
+
# Usage example for the simple version
|
| 141 |
+
# dividend_info = simple_dividend_extraction('text.html')
|
| 142 |
+
# for info in dividend_info:
|
| 143 |
+
# print(f"Company: {info['Company']}, Dividend: {info['Dividend']}, Date: {info['Date']}")
|
| 144 |
+
|
| 145 |
@app.get("/hello")
|
| 146 |
def greet_json():
|
| 147 |
return {"Hello": "World!"}
|
|
|
|
| 149 |
|
| 150 |
@app.get("/dividend_history")
|
| 151 |
def get_dividend():
|
| 152 |
+
return simple_dividend_extraction()
|
| 153 |
|
| 154 |
|
| 155 |
|