Created
October 12, 2017 18:17
-
-
Save twainy/7340894a5d2c5e89230685a6766cd2d5 to your computer and use it in GitHub Desktop.
Fire emblem heroes の 劣勢通知
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from bs4 import BeautifulSoup | |
import smtplib | |
from email.mime.text import MIMEText | |
from urllib import request | |
import os | |
url = 'https://support.fire-emblem-heroes.com/voting_gauntlet/tournaments/%s' | |
tournament_id = 7 | |
my_target = 'カムイ' | |
to_addr = os.getenv('TOADDR') | |
from_addr = os.getenv('FROMADDR') | |
with request.urlopen(url % tournament_id) as response: | |
html = response.read() | |
soup = BeautifulSoup(html, 'html.parser') | |
articles = soup.find_all('article', {'class':'body-section-tournament'}) | |
# 一番上はトーナメント表なので二番目を取得する | |
elm_list = [] | |
hero_situation = {} | |
for elm in articles[1].find_all('div', {'class':'tournaments-art-left'}): | |
elm_list.append(elm) | |
for elm in articles[1].find_all('div', {'class':'tournaments-art-right'}): | |
elm_list.append(elm) | |
for elm in elm_list: | |
name = elm.find('p', {'class':'name'}).string | |
situation_class_name = elm['class'][1] | |
situation = situation_class_name.split('-')[-1] | |
hero_situation[name] = situation | |
message =MIMEText('', 'plain', 'iso-2022-jp') | |
if (hero_situation[my_target] == 'behind'): | |
message['Subject'] = '%s が劣勢だよ!' % my_target | |
message['From'] = from_addr | |
message['To'] = to_addr | |
server = smtplib.SMTP('localhost') | |
server.send_message(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment