続けて、LINEで天気予報の情報を毎朝自分に送信するプログラムを作成。
google homeで聞いたら一発で教えてくれるのだが、朝起きて一番初めにすることはLINEを見ることの場合が多く、意外に便利だなと思った。
LINEnotifyトークンIDは此方から簡単に発行可能。LINEアカウントでログインして、LINEnotifyの利用登録後トークン発行ボタンを押せばOK
タスクスケジューラを使用して、こちらのコードをexe化して、毎朝起動するように設定すればメッセージを受け取れるようになる。
(コード)
import requests
import urllib.request as urlreq
from bs4 import BeautifulSoup
r = requests.get("https://tenki.jp/forecast/3/15/4510/12227/10days.html")
weather_list = []
soup = BeautifulSoup(r.content, "html.parser")
weatherinf0 = soup.table.tr.nextSibling.nextSibling
#print(weatherinf0.txt)
weatherinf1 = weatherinf0.nextSibling.nextSibling
weatherinf2 = weatherinf1.nextSibling.nextSibling
weatherinf3 = weatherinf2.nextSibling.nextSibling
weather_list.append(weatherinf0.text)
weather_list.append(weatherinf1.text)
weather_list.append(weatherinf2.text)
weather_list.append(weatherinf3.text)
#print("全容の確認", weather_list)
#print("確認", weather_list[0])
temp_list = []
for i in range(len(weather_list)):
temp = weather_list[i].split('\n\n\n')
mojiretu = ','.join(temp)
mojiretu = mojiretu.replace(',', '')
print("確認", mojiretu)
temp_list.append(mojiretu)
#print("確認", mojiretu)
print("リストのかくにん", temp_list)
line_notify_token = '(LINEnotifyトークン)'
line_notify_api = 'https://notify-api.line.me/api/notify'
#payload = {'message': weather_list}
payload = {'message': temp_list}
headers = {'Authorization': 'Bearer ' + line_notify_token} # 発行したトークン
line_notify = requests.post(line_notify_api, data=payload, headers=headers)
以上