from flask import Flask
from flask_cors import CORS
import requests
import random
import json
from datetime import datetime
app = Flask(__name__)
CORS(app)
def fetch_eth_data():
try:
headers = {
'x-cg-demo-api-key': 'CG-AA9irFbKztQh3VTVDHRoeZVH'
}
response = requests.get(
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=eur",
headers=headers
)
response.raise_for_status()
return float(response.json()["ethereum"]["eur"])
except Exception as e:
raise Exception(f"Fehler beim Abrufen des Ethereum-Preises: {e}")
def generate_forecast(base_price):
forecast = {}
years = [2025, 2026, 2030]
current_year = datetime.now().year
for year in years:
years_ahead = max(1, year - current_year)
optimistic_price = base_price * ((1 + random.uniform(0.4, 0.6)) ** years_ahead)
average_price = base_price * ((1 + random.uniform(0.2, 0.3)) ** years_ahead)
pessimistic_price = base_price * ((1 + random.uniform(0.05, 0.1)) ** years_ahead)
forecast[year] = {
"optimistisch": (
round(optimistic_price, 2),
round(((optimistic_price - base_price) / base_price) * 100, 2)
),
"durchschnittlich": (
round(average_price, 2),
round(((average_price - base_price) / base_price) * 100, 2)
),
"pessimistisch": (
round(pessimistic_price, 2),
round(((pessimistic_price - base_price) / base_price) * 100, 2)
)
}
return forecast
@app.route('/')
def index():
try:
base_price = fetch_eth_data()
forecast = generate_forecast(base_price)
forecast_json = json.dumps({
year: {
key: forecast[year][key][0]
for key in forecast[year]
} for year in forecast
})
html = f"""
<!DOCTYPE html>
<html>
<head>
<title>Ethereum Prognose</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {{
font-family: 'Segoe UI', sans-serif;
background: transparent;
color: #000;
margin: 0;
padding: 20px;
}}
.container {{
max-width: 1200px;
margin: auto;
}}
h1 {{
text-align: center;
margin-bottom: 20px;
}}
.current-price {{
padding: 15px;
text-align: center;
font-size: 1.3em;
margin-bottom: 30px;
}}
.year-container {{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}}
.year-card {{
background: rgba(255, 253, 208, 0.95);
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}}
.chart-container {{
background: #fff;
border-radius: 10px;
padding: 10px;
}}
.forecast-data p {{
background: rgba(0, 0, 0, 0.05);
margin: 8px 0;
padding: 10px;
border-radius: 8px;
}}
</style>
</head>
<body>
<div class="container">
<h1>Ethereum Prognose</h1>
<div class="current-price">Aktueller ETH Preis: € {base_price:.2f}</div>
<div class="year-container">
"""
for year in forecast:
html += f"""
<div class="year-card">
<h2>{year}</h2>
<div class="chart-container">
<canvas id="chart{year}" height="250"></canvas>
</div>
<div class="forecast-data">
<p><strong>Optimistisch:</strong> € {forecast[year]["optimistisch"][0]} (+{forecast[year]["optimistisch"][1]:.2f}%)</p>
<p><strong>Durchschnittlich:</strong> € {forecast[year]["durchschnittlich"][0]} (+{forecast[year]["durchschnittlich"][1]:.2f}%)</p>
<p><strong>Pessimistisch:</strong> € {forecast[year]["pessimistisch"][0]} (+{forecast[year]["pessimistisch"][1]:.2f}%)</p>
</div>
</div>
"""
html += f"""
</div>
</div>
<script>
const base_price = {base_price};
const forecastData = {forecast_json};
function createChart(ctx, prices, year) {{
new Chart(ctx, {{
type: 'line',
data: {{
labels: ['Jetzt', year],
datasets: [
{{
label: 'Pessimistisch',
data: [base_price, prices['pessimistisch']],
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.1)',
fill: '-1',
tension: 0.3,
pointRadius: 5,
borderWidth: 2
}},
{{
label: 'Durchschnittlich',
data: [base_price, prices['durchschnittlich']],
borderColor: 'rgba(54, 162, 235, 1)',
borderDash: [5, 5],
tension: 0.3,
pointRadius: 5,
borderWidth: 2
}},
{{
label: 'Optimistisch',
data: [base_price, prices['optimistisch']],
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.1)',
fill: '-1',
tension: 0.3,
pointRadius: 5,
borderWidth: 2
}}
]
}},
options: {{
responsive: true,
plugins: {{
legend: {{
labels: {{ color: '#000' }}
}},
title: {{
display: true,
text: 'Preisprognose ' + year,
color: '#000'
}}
}},
scales: {{
y: {{
beginAtZero: false,
ticks: {{ color: '#000' }},
title: {{
display: true,
text: 'Preis (EUR)',
color: '#000'
}}
}},
x: {{
ticks: {{ color: '#000' }}
}}
}}
}}
}});
}}
Object.entries(forecastData).forEach(([year, prices]) => {{
createChart(document.getElementById('chart' + year), prices, year);
}});
</script>
</body>
</html>
"""
return html
except Exception as e:
return f"<h2>Fehler: {str(e)}</h2>"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)