wlstp8473

python json파일 생성 코드

1 +# -*- coding: utf-8 -*-
2 +import json
3 +
1 import telegram 4 import telegram
2 from telegram.ext import Updater 5 from telegram.ext import Updater
3 from telegram.ext import MessageHandler, Filters 6 from telegram.ext import MessageHandler, Filters
...@@ -16,7 +19,7 @@ def covid_num_crawling(): ...@@ -16,7 +19,7 @@ def covid_num_crawling():
16 soup = BeautifulSoup(code, "html.parser") 19 soup = BeautifulSoup(code, "html.parser")
17 info_num = soup.select("div.status_today em") 20 info_num = soup.select("div.status_today em")
18 result = int(info_num[0].string) + int(info_num[1].string) 21 result = int(info_num[0].string) + int(info_num[1].string)
19 - return result 22 + return resul
20 23
21 def covid_news_crawling(): 24 def covid_news_crawling():
22 code = req.urlopen("https://search.naver.com/search.naver?where=news&sm=tab_jum&query=%EC%BD%94%EB%A1%9C%EB%82%98") 25 code = req.urlopen("https://search.naver.com/search.naver?where=news&sm=tab_jum&query=%EC%BD%94%EB%A1%9C%EB%82%98")
...@@ -32,6 +35,15 @@ def covid_news_crawling(): ...@@ -32,6 +35,15 @@ def covid_news_crawling():
32 return output_result 35 return output_result
33 36
34 37
38 + def toJson(mnet_dict):
39 + with open('mnet_chart.json', 'w', encoding='utf-8') as file :
40 + json.dump(mnet_dict, file, ensure_ascii=False, indent='\t')
41 +
42 +
43 +
44 +
45 +
46 +
35 #텔레그램 관련 코드 47 #텔레그램 관련 코드
36 token = "1721885449:AAHDGMbjSJfhXxML6nfSCpfiU7SghpL_vOE" 48 token = "1721885449:AAHDGMbjSJfhXxML6nfSCpfiU7SghpL_vOE"
37 id = "1657858421" 49 id = "1657858421"
...@@ -77,4 +89,3 @@ def handler(update, context): ...@@ -77,4 +89,3 @@ def handler(update, context):
77 echo_handler = MessageHandler(Filters.text, handler) 89 echo_handler = MessageHandler(Filters.text, handler)
78 dispatcher.add_handler(echo_handler) 90 dispatcher.add_handler(echo_handler)
79 91
80 -
......