I'm a high school student. The school will be closed due to an alarm. The pious time to check the alarms one by one on that poorly responsive NHK data broadcast is too exciting, so I would like you to be notified automatically on Twitter. Yes.
Somehow, there is no alarm API at all. I found it when I was looking for it, but apparently it seems that I'm using a bubbly protocol called "Habusabu Pab Bab".
...
This is it !!
It feels like it.
# coding: UTF-8
#!/usr/bin/env python3
from urllib import request
from bs4 import BeautifulSoup
from datetime import datetime
import time
import twitter
OK = '33[92m'
WARN = '33[93m'
NG = '33[91m'
END_CODE = '33[0m'
api = twitter.Api(consumer_key='Oh your', consumer_secret='Secret', access_token_secret='I'll put it here')
#URL to access
url = "https://typhoon.yahoo.co.jp/weather/jp/warn/Something/number/"
def Getter(soup):
Summaryarea = soup.findAll("div", class_="warnSummary_box")
# print(Summaryarea[0].dl)
Li = Summaryarea[0].dl.dd.ul.li
# adv = Li.find("span",class_="icoAdvisory")#Alert notification
adv = Li.find("span", class_="icoWarning") #Notice
if adv:
# Yes
# print("OK")
return 1
else:
# No
# print("NO")
return 0
def Twit(state):
nowtime = datetime.now()
NowStr = str(nowtime.hour) + "Time" + str(nowtime.minute) + "Minutes now"
Txt = ""
if state:
Txt = "\n It seems that an alarm has been issued to the city somehow. .. ..\n I'm not happy because I'm on school holidays! !!"
else:
Txt = "\n It seems that there is no warning in the city somehow.\n Stop the weird bad luck and go to school quickly."
status = api.PostUpdate("[Weather warning automatic notification system]\n" + NowStr + Txt)
print(status.text)
def Coloring(txt, code):
return "\033[%sm%s\033[0m" % (code, txt)
def main():
while 1:
print("Now " + ntStr)
print("Its time!")
#Read
html = request.urlopen(url).read()
soup = BeautifulSoup(html, "html.parser")
Twit(Getter(soup))
if Getter(soup):
#With an alarm
print(Coloring("!!!!WARNING!!!!", "31"))
else:
#Don't get an alarm
print(Coloring("ALLGREEN", "32"))
time.sleep(60 * 3)
if __name__ == "__main__":
main()
I can do it.
Good vibes.
Link this with Raspberry Pi to lock the house when an alarm is issued www
Recommended Posts