Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Fire emblem heroes の 劣勢通知
# -*- 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