update
This commit is contained in:
@@ -247,6 +247,70 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% if transport_disruptions and transport_disruptions|length > 0 %}
|
||||
<!-- Divider -->
|
||||
<tr>
|
||||
<td style="padding: 0 40px;">
|
||||
<div style="height: 2px; background-color: #e0e0e0;"></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Transport Disruptions Section -->
|
||||
<tr>
|
||||
<td style="padding: 30px 40px;">
|
||||
<h2 style="margin: 0 0 20px 0; font-size: 22px; font-weight: 700; color: #1a1a1a;">
|
||||
🚆 S-Bahn Disruptions Today
|
||||
</h2>
|
||||
<p style="margin: 0 0 20px 0; font-size: 14px; color: #666666;">
|
||||
Current service disruptions affecting Munich S-Bahn:
|
||||
</p>
|
||||
|
||||
{% for disruption in transport_disruptions %}
|
||||
<!-- Disruption Card -->
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 15px; background-color: #fff8f0; border-left: 4px solid #ff9800; border-radius: 4px;">
|
||||
<tr>
|
||||
<td style="padding: 15px 20px;">
|
||||
<!-- Severity and Lines -->
|
||||
<p style="margin: 0 0 8px 0; font-size: 13px; color: #666666;">
|
||||
{{ disruption.severity_icon }} <strong style="color: #000000;">{{ disruption.lines_str }}</strong>
|
||||
</p>
|
||||
|
||||
<!-- Title -->
|
||||
<p style="margin: 0 0 8px 0; font-size: 15px; font-weight: 700; color: #1a1a1a; line-height: 1.4;">
|
||||
{{ disruption.title }}
|
||||
</p>
|
||||
|
||||
<!-- Description -->
|
||||
{% if disruption.description %}
|
||||
<p style="margin: 0 0 8px 0; font-size: 14px; color: #333333; line-height: 1.5;">
|
||||
{{ disruption.description }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- Time -->
|
||||
{% if disruption.start_time_str or disruption.end_time_str %}
|
||||
<p style="margin: 0; font-size: 13px; color: #666666;">
|
||||
⏰
|
||||
{% if disruption.start_time_str %}
|
||||
From {{ disruption.start_time_str }}
|
||||
{% endif %}
|
||||
{% if disruption.end_time_str %}
|
||||
until {{ disruption.end_time_str }}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endfor %}
|
||||
|
||||
<p style="margin: 15px 0 0 0; font-size: 12px; color: #999999; font-style: italic;">
|
||||
💡 Plan your commute accordingly. Check <a href="https://www.mvg.de" style="color: #667eea; text-decoration: none;">MVG.de</a> for real-time updates.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
<!-- Footer -->
|
||||
<tr>
|
||||
<td style="background-color: #1a1a1a; padding: 30px 40px; text-align: center;">
|
||||
|
||||
@@ -77,6 +77,72 @@ client = MongoClient(Config.MONGODB_URI)
|
||||
db = client[Config.DB_NAME]
|
||||
articles_collection = db['articles']
|
||||
subscribers_collection = db['subscribers']
|
||||
transport_alerts_collection = db['transport_alerts']
|
||||
|
||||
|
||||
def get_today_transport_disruptions():
|
||||
"""
|
||||
Get active S-Bahn disruptions for today
|
||||
Fetches from MongoDB transport_alerts collection
|
||||
|
||||
Returns:
|
||||
list: Active disruptions with details
|
||||
"""
|
||||
try:
|
||||
from datetime import datetime
|
||||
|
||||
# Get active disruptions
|
||||
disruptions = list(transport_alerts_collection.find(
|
||||
{'is_active': True},
|
||||
{'_id': 0}
|
||||
).sort('severity', -1).sort('updated_at', -1))
|
||||
|
||||
# Filter for disruptions happening today
|
||||
today = datetime.utcnow().date()
|
||||
today_disruptions = []
|
||||
|
||||
for d in disruptions:
|
||||
# Check if disruption is active today
|
||||
start_time = d.get('start_time')
|
||||
end_time = d.get('end_time')
|
||||
|
||||
is_today = False
|
||||
if start_time and end_time:
|
||||
start_date = start_time.date() if hasattr(start_time, 'date') else today
|
||||
end_date = end_time.date() if hasattr(end_time, 'date') else today
|
||||
is_today = start_date <= today <= end_date
|
||||
elif start_time:
|
||||
start_date = start_time.date() if hasattr(start_time, 'date') else today
|
||||
is_today = start_date <= today
|
||||
else:
|
||||
is_today = True # No time info, assume it's relevant
|
||||
|
||||
if is_today:
|
||||
# Format times for display
|
||||
if start_time:
|
||||
d['start_time_str'] = start_time.strftime('%H:%M') if hasattr(start_time, 'strftime') else str(start_time)
|
||||
if end_time:
|
||||
d['end_time_str'] = end_time.strftime('%H:%M') if hasattr(end_time, 'strftime') else str(end_time)
|
||||
|
||||
# Format lines as comma-separated string
|
||||
d['lines_str'] = ', '.join(d.get('lines', []))
|
||||
|
||||
# Get severity icon
|
||||
severity_icons = {
|
||||
'high': '🔴',
|
||||
'medium': '🟡',
|
||||
'low': '🟢'
|
||||
}
|
||||
d['severity_icon'] = severity_icons.get(d.get('severity', 'medium'), '🟡')
|
||||
|
||||
today_disruptions.append(d)
|
||||
|
||||
print(f"✓ Found {len(today_disruptions)} transport disruptions for today")
|
||||
return today_disruptions
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ Error fetching transport disruptions: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_latest_articles_by_categories(categories=None, articles_per_category=3, hours=24):
|
||||
@@ -296,6 +362,9 @@ def render_newsletter_html(articles, subscriber_categories=None, tracking_enable
|
||||
from weather_service import get_munich_weather
|
||||
weather = get_munich_weather()
|
||||
|
||||
# Get transport disruptions for today
|
||||
transport_disruptions = get_today_transport_disruptions()
|
||||
|
||||
# Prepare template data
|
||||
now = datetime.now()
|
||||
total_articles = sum(len(section['articles']) for section in category_sections)
|
||||
@@ -308,7 +377,8 @@ def render_newsletter_html(articles, subscriber_categories=None, tracking_enable
|
||||
'preferences_link': f'{Config.WEBSITE_URL}/preferences.html',
|
||||
'website_link': Config.WEBSITE_URL,
|
||||
'tracking_enabled': tracking_enabled,
|
||||
'weather': weather
|
||||
'weather': weather,
|
||||
'transport_disruptions': transport_disruptions
|
||||
}
|
||||
|
||||
# Render HTML
|
||||
|
||||
Reference in New Issue
Block a user