Update app.py
Browse files
app.py
CHANGED
@@ -36,14 +36,22 @@ KOREAN_COMPANIES = [
|
|
36 |
|
37 |
def convert_to_seoul_time(timestamp_str):
|
38 |
try:
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
42 |
-
|
|
|
|
|
|
|
43 |
return seoul_time.strftime('%Y-%m-%d %H:%M:%S KST')
|
44 |
-
except:
|
|
|
45 |
return timestamp_str
|
46 |
|
|
|
|
|
47 |
def analyze_sentiment_batch(articles, client):
|
48 |
try:
|
49 |
# 모든 기사의 제목과 내용을 하나의 텍스트로 결합
|
@@ -93,20 +101,22 @@ def init_db():
|
|
93 |
conn.commit()
|
94 |
conn.close()
|
95 |
|
96 |
-
# 검색 결과 저장 함수
|
97 |
def save_to_db(keyword, country, results):
|
98 |
conn = sqlite3.connect("search_results.db")
|
99 |
c = conn.cursor()
|
100 |
|
101 |
-
# 서울 시간으로
|
102 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
103 |
-
|
|
|
|
|
|
|
104 |
|
105 |
c.execute("""INSERT INTO searches
|
106 |
(keyword, country, results, timestamp)
|
107 |
VALUES (?, ?, ?, ?)""",
|
108 |
-
(keyword, country, json.dumps(results),
|
109 |
-
|
110 |
conn.commit()
|
111 |
conn.close()
|
112 |
|
|
|
36 |
|
37 |
def convert_to_seoul_time(timestamp_str):
|
38 |
try:
|
39 |
+
# 입력된 시간을 naive datetime 객체로 변환
|
40 |
+
dt = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
|
41 |
+
|
42 |
+
# 서울 시간대 설정
|
43 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
44 |
+
|
45 |
+
# 현재 시간을 서울 시간으로 인식하도록 수정
|
46 |
+
seoul_time = seoul_tz.localize(dt)
|
47 |
+
|
48 |
return seoul_time.strftime('%Y-%m-%d %H:%M:%S KST')
|
49 |
+
except Exception as e:
|
50 |
+
print(f"시간 변환 오류: {str(e)}")
|
51 |
return timestamp_str
|
52 |
|
53 |
+
|
54 |
+
|
55 |
def analyze_sentiment_batch(articles, client):
|
56 |
try:
|
57 |
# 모든 기사의 제목과 내용을 하나의 텍스트로 결합
|
|
|
101 |
conn.commit()
|
102 |
conn.close()
|
103 |
|
|
|
104 |
def save_to_db(keyword, country, results):
|
105 |
conn = sqlite3.connect("search_results.db")
|
106 |
c = conn.cursor()
|
107 |
|
108 |
+
# 현재 시간을 서울 시간으로 가져오기
|
109 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
110 |
+
now = datetime.now(seoul_tz)
|
111 |
+
|
112 |
+
# 시간대 정보를 제거하고 저장
|
113 |
+
timestamp = now.strftime('%Y-%m-%d %H:%M:%S')
|
114 |
|
115 |
c.execute("""INSERT INTO searches
|
116 |
(keyword, country, results, timestamp)
|
117 |
VALUES (?, ?, ?, ?)""",
|
118 |
+
(keyword, country, json.dumps(results), timestamp))
|
119 |
+
|
120 |
conn.commit()
|
121 |
conn.close()
|
122 |
|