Update app.py
Browse files
app.py
CHANGED
@@ -48,19 +48,24 @@ TIMEZONE_CITIES = {
|
|
48 |
"λ² μ΄μ»€ μ¬ (UTC-12)": -12,
|
49 |
}
|
50 |
|
51 |
-
def convert_to_seoul_time(year, month, day, hour, minute,
|
52 |
"""
|
53 |
μ νλ μκ°λμ μκ°μ μμΈ μκ°μΌλ‘ λ³ν
|
54 |
"""
|
55 |
try:
|
56 |
-
#
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# μμΈκ³Όμ μμ°¨ κ³μ° (μμΈμ UTC+9)
|
60 |
time_difference = 9 - timezone_offset
|
61 |
|
62 |
# μ
λ ₯ μκ° μμ±
|
63 |
-
local_time = datetime(
|
64 |
|
65 |
# μμ°¨ μ μ©
|
66 |
seoul_time = local_time + timedelta(hours=time_difference)
|
@@ -72,7 +77,59 @@ def convert_to_seoul_time(year, month, day, hour, minute, timezone_name):
|
|
72 |
'hour': f"{seoul_time.hour:02d}{seoul_time.minute:02d}"
|
73 |
}
|
74 |
except Exception as e:
|
75 |
-
raise Exception(f"μκ° λ³ν μ€ μ€λ₯ λ°μ: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
|
78 |
def exception_handler(exception_type, exception, traceback):
|
@@ -170,55 +227,7 @@ def calculate_siju(birth_hour, lunIljin):
|
|
170 |
return siju
|
171 |
|
172 |
|
173 |
-
|
174 |
-
try:
|
175 |
-
# μ
λ ₯κ° κ²μ¦
|
176 |
-
if not all([solYear, solMonth, solDay, solHour, timezone_name]):
|
177 |
-
raise ValueError("λͺ¨λ νλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ.")
|
178 |
-
|
179 |
-
# μκ° νμ±
|
180 |
-
hour = int(solHour[:2])
|
181 |
-
minute = int(solHour[2:]) if len(solHour) > 2 else 0
|
182 |
-
|
183 |
-
# μκ° λ²μ κ²μ¦
|
184 |
-
if not (0 <= hour <= 23) or not (0 <= minute <= 59):
|
185 |
-
raise ValueError("μ¬λ°λ₯Έ μκ° νμμ΄ μλλλ€.")
|
186 |
-
|
187 |
-
# μ νλ μκ°λμμ μμΈ μκ°μΌλ‘ λ³ν
|
188 |
-
seoul_time = convert_to_seoul_time(solYear, solMonth, solDay, hour, minute, timezone_name)
|
189 |
-
|
190 |
-
|
191 |
-
base_url = "http://apis.data.go.kr/B090041/openapi/service/LrsrCldInfoService/getLunCalInfo"
|
192 |
-
service_key = "EuBjt%2B2t0KzYt5Ri%2Bzs56oymt9kHJ8uPIOV7m6UMKnOV8cpwj02EiRqMEudX%2F%2FVTKdMnwaLH0igRwY57YUplEQ%3D%3D"
|
193 |
-
|
194 |
-
url = f"{base_url}?solYear={seoul_time['year']}&solMonth={seoul_time['month']}&solDay={seoul_time['day']}&ServiceKey={service_key}"
|
195 |
-
|
196 |
-
response = requests.get(url)
|
197 |
-
if response.status_code == 200:
|
198 |
-
root = ElementTree.fromstring(response.content)
|
199 |
-
|
200 |
-
lunIljin = root.find(".//lunIljin").text if root.find(".//lunIljin") is not None else "μ 보 μμ"
|
201 |
-
lunWolgeon = root.find(".//lunWolgeon").text if root.find(".//lunWolgeon") is not None else "μ 보 μμ"
|
202 |
-
lunSecha = root.find(".//lunSecha").text if root.find(".//lunSecha") is not None else "μ 보 μμ"
|
203 |
-
|
204 |
-
siju = calculate_siju(seoul_time['hour'], lunIljin)
|
205 |
-
analysis_html = μ¬μ£Ό_λΆμ(lunSecha, lunWolgeon, lunIljin, siju)
|
206 |
-
|
207 |
-
# μλ³Έ μκ°κ³Ό λ³νλ μμΈ μκ° μ 보λ₯Ό ν¬ν¨ν κ²°κ³Ό
|
208 |
-
result = {
|
209 |
-
"μ
λ ₯ μκ°": f"{timezone_name}: {solYear}λ
{solMonth}μ {solDay}μΌ {hour:02d}μ {minute:02d}λΆ",
|
210 |
-
"λ³νλ μμΈ μκ°": f"{seoul_time['year']}λ
{seoul_time['month']}μ {seoul_time['day']}μΌ {seoul_time['hour'][:2]}μ {seoul_time['hour'][2:]}λΆ",
|
211 |
-
"λ
μ£Ό": lunSecha,
|
212 |
-
"μμ£Ό": lunWolgeon,
|
213 |
-
"μΌμ£Ό": lunIljin,
|
214 |
-
"μμ£Ό": siju
|
215 |
-
}
|
216 |
-
|
217 |
-
return result, lunIljin, analysis_html
|
218 |
-
else:
|
219 |
-
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
220 |
-
except Exception as e:
|
221 |
-
return {"Error": f"μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"}, "μ 보 μμ", "<p>μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€.</p>"
|
222 |
|
223 |
def analyze_character(lunIljin):
|
224 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
|
|
48 |
"λ² μ΄μ»€ μ¬ (UTC-12)": -12,
|
49 |
}
|
50 |
|
51 |
+
def convert_to_seoul_time(year, month, day, hour, minute, timezone_offset):
|
52 |
"""
|
53 |
μ νλ μκ°λμ μκ°μ μμΈ μκ°μΌλ‘ λ³ν
|
54 |
"""
|
55 |
try:
|
56 |
+
# μ
λ ₯κ°μ μ μλ‘ λ³ν
|
57 |
+
year = int(year)
|
58 |
+
month = int(month)
|
59 |
+
day = int(day)
|
60 |
+
hour = int(hour)
|
61 |
+
minute = int(minute)
|
62 |
+
timezone_offset = float(timezone_offset) # μ¬λΌμ΄λ κ°μ floatλ‘ μ²λ¦¬
|
63 |
|
64 |
# μμΈκ³Όμ μμ°¨ κ³μ° (μμΈμ UTC+9)
|
65 |
time_difference = 9 - timezone_offset
|
66 |
|
67 |
# μ
λ ₯ μκ° μμ±
|
68 |
+
local_time = datetime(year, month, day, hour, minute)
|
69 |
|
70 |
# μμ°¨ μ μ©
|
71 |
seoul_time = local_time + timedelta(hours=time_difference)
|
|
|
77 |
'hour': f"{seoul_time.hour:02d}{seoul_time.minute:02d}"
|
78 |
}
|
79 |
except Exception as e:
|
80 |
+
raise Exception(f"μκ° λ³ν μ€ μ€λ₯ λ°μ: {str(e)}\nμ
λ ₯κ°: year={year}, month={month}, day={day}, hour={hour}, minute={minute}, offset={timezone_offset}")
|
81 |
+
|
82 |
+
def get_lunar_info(solYear, solMonth, solDay, solHour, timezone_offset):
|
83 |
+
try:
|
84 |
+
# μ
λ ₯κ° κ²μ¦
|
85 |
+
if not all([solYear, solMonth, solDay, solHour]):
|
86 |
+
raise ValueError("λͺ¨λ νλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ.")
|
87 |
+
|
88 |
+
# μκ° νμ±
|
89 |
+
try:
|
90 |
+
hour = int(solHour[:2])
|
91 |
+
minute = int(solHour[2:]) if len(solHour) > 2 else 0
|
92 |
+
except ValueError:
|
93 |
+
raise ValueError("μ¬λ°λ₯Έ μκ° νμμ΄ μλλλ€. (μ: 1430)")
|
94 |
+
|
95 |
+
# μκ° λ²μ κ²μ¦
|
96 |
+
if not (0 <= hour <= 23) or not (0 <= minute <= 59):
|
97 |
+
raise ValueError("μ¬λ°λ₯Έ μκ° λ²μκ° μλλλ€.")
|
98 |
+
|
99 |
+
# μ νλ μκ°λμμ μμΈ μκ°μΌλ‘ λ³ν
|
100 |
+
seoul_time = convert_to_seoul_time(solYear, solMonth, solDay, hour, minute, timezone_offset)
|
101 |
+
|
102 |
+
base_url = "http://apis.data.go.kr/B090041/openapi/service/LrsrCldInfoService/getLunCalInfo"
|
103 |
+
service_key = "EuBjt%2B2t0KzYt5Ri%2Bzs56oymt9kHJ8uPIOV7m6UMKnOV8cpwj02EiRqMEudX%2F%2FVTKdMnwaLH0igRwY57YUplEQ%3D%3D"
|
104 |
+
|
105 |
+
url = f"{base_url}?solYear={seoul_time['year']}&solMonth={seoul_time['month']}&solDay={seoul_time['day']}&ServiceKey={service_key}"
|
106 |
+
|
107 |
+
response = requests.get(url)
|
108 |
+
if response.status_code == 200:
|
109 |
+
root = ElementTree.fromstring(response.content)
|
110 |
+
|
111 |
+
lunIljin = root.find(".//lunIljin").text if root.find(".//lunIljin") is not None else "μ 보 μμ"
|
112 |
+
lunWolgeon = root.find(".//lunWolgeon").text if root.find(".//lunWolgeon") is not None else "μ 보 μμ"
|
113 |
+
lunSecha = root.find(".//lunSecha").text if root.find(".//lunSecha") is not None else "μ 보 μμ"
|
114 |
+
|
115 |
+
siju = calculate_siju(seoul_time['hour'], lunIljin)
|
116 |
+
analysis_html = μ¬μ£Ό_λΆμ(lunSecha, lunWolgeon, lunIljin, siju)
|
117 |
+
|
118 |
+
# μλ³Έ μκ°κ³Ό λ³νλ μμΈ μκ° μ 보λ₯Ό ν¬ν¨ν κ²°κ³Ό
|
119 |
+
result = {
|
120 |
+
"μ
λ ₯ μκ°": f"UTC{'+' if timezone_offset > 0 else ''}{timezone_offset}: {solYear}λ
{solMonth}μ {solDay}μΌ {hour:02d}μ {minute:02d}λΆ",
|
121 |
+
"λ³νλ μμΈ μκ°": f"{seoul_time['year']}λ
{seoul_time['month']}μ {seoul_time['day']}μΌ {seoul_time['hour'][:2]}μ {seoul_time['hour'][2:]}λΆ",
|
122 |
+
"λ
μ£Ό": lunSecha,
|
123 |
+
"μμ£Ό": lunWolgeon,
|
124 |
+
"μΌμ£Ό": lunIljin,
|
125 |
+
"μμ£Ό": siju
|
126 |
+
}
|
127 |
+
|
128 |
+
return result, lunIljin, analysis_html
|
129 |
+
else:
|
130 |
+
return {"Error": "API νΈμΆμ μ€ν¨νμ΅λλ€."}, "μ 보 μμ", "<p>API νΈμΆμ μ€ν¨νμ΅λλ€.</p>"
|
131 |
+
except Exception as e:
|
132 |
+
return {"Error": f"μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"}, "μ 보 μμ", "<p>μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€.</p>"
|
133 |
|
134 |
|
135 |
def exception_handler(exception_type, exception, traceback):
|
|
|
227 |
return siju
|
228 |
|
229 |
|
230 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
def analyze_character(lunIljin):
|
233 |
API_URL = "https://api.openai.com/v1/chat/completions"
|