-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (34 loc) · 1.38 KB
/
Copy pathutils.py
File metadata and controls
38 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import sys
# Helper function to save the weather data in forecast.html
def save_forecast_as_html(forecast, location, temperatur_chart):
# Determine the directory where the executable is located
if getattr(sys, 'frozen', False):
# If running in a frozen environment (e.g., PyInstaller)
html_file_path = 'forecast.html'
# Directory where the .exe is located
exe_dir = os.path.dirname(sys.executable)
else:
# If running in a normal Python environment
html_file_path = 'index.html'
exe_dir = os.path.dirname(os.path.abspath(__file__))
# Define the path for the HTML file in the same directory as the executable
html_file_path = os.path.join(exe_dir, html_file_path)
# Write the HTML content to the file
with open(html_file_path, 'w') as file:
file.write(f'''
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>14 Tage Wettervorhersage</title>
</head>
<body>
<h1>14 Tage Wettervorhersage für {location}</h1>
<pre>{forecast}</pre>
<h2>Temperatur Chart</h2>
<img src="{temperatur_chart}" alt="Temperature Chart">
</body>
</html>
''')
print(f"Forecast has been saved to {html_file_path}")