-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
138 lines (109 loc) · 3.03 KB
/
Copy pathconfig.py
File metadata and controls
138 lines (109 loc) · 3.03 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import streamlit as st
import requests as rq
from contextlib import contextmanager
import csv
#-------------------USEFUL MAPS----------------------------------------------------
#Weather Mapping
weather_map = {
0: "Clear sky",
1: "Mainly clear",
2: "Partly cloudy",
3: "Overcast",
45: "Fog",
48: "Depositing rime fog",
51: "Light drizzle",
53: "Moderate drizzle",
55: "Dense drizzle",
61: "Light rain",
63: "Moderate rain",
65: "Heavy rain",
71: "Light snow",
73: "Moderate snow",
75: "Heavy snow",
80: "Rain showers",
81: "Moderate rain showers",
82: "Violent rain showers",
95: "Thunderstorm",
96: "Thunderstorm with hail",
99: "Heavy thunderstorm with hail"
}
#URL for getting the current weather
urls = {
"url_weather_forcast" : "https://api.open-meteo.com/v1/forecast",
"url_location_finder" : "http://ip-api.com/json/",
"url_energy_facts" : "https://en.wikipedia.org/api/rest_v1/page/summary/Energy"
}
#PATHS necessary
paths = {
"gif_path" : "LoadingScreens/RippleLoad.gif"
}
#-----------------FUNCTIONS-----------------------------------------------
@st.cache_data(show_spinner=False)
def get_user_location():
try:
response = rq.get(urls["url_location_finder"])
data = response.json()
location = {
"city": data.get("city", "Unknown"),
"latitude": data.get("lat", 0),
"longitude": data.get("lon", 0),
"accurate": True
}
return location
except:
return {
"city": "Chennai",
"latitude": 13.0827,
"longitude": 80.2707,
"accurate": False
}
@st.cache_data(show_spinner=False)
def getWeatherData(params):
try:
data = rq.get(urls["url_weather_forcast"], params=params).json()
weather_data = data["current"]
return weather_data
except:
return {}
@st.cache_data(show_spinner=False)
def getFakeData():
fake_data = rq.get("https://jsonplaceholder.typicode.com/todos/1")
return fake_data
def fullscreen_loader(gif_path):
import base64
with open(gif_path, "rb") as f:
b64data = base64.b64encode(f.read()).decode()
loader_html = f"""
<div id="loader-overlay">
<img src="data:image/gif;base64,{b64data}" />
</div>
<style>
#loader-overlay {{
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
z-index: 999999;
clip-path: circle(150% at 50% 50%);
transition: clip-path 0.8s ease-out;
}}
#loader-overlay.shockwave {{
clip-path: circle(0% at 50% 50%);
}}
#loader-overlay img {{
width: 50vw;
max-width: 600px;
}}
</style>
"""
return st.markdown(loader_html, unsafe_allow_html=True)
#----------------------------------------------------------------------------------
def write_to(csv_file, data):
with open(csv_file, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)