Created
March 10, 2019 15:55
-
-
Save k-aota/9d5e0574908d15906af6bf441514bf19 to your computer and use it in GitHub Desktop.
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 | |
# python3用です | |
# 公開用 | |
import requests | |
import urllib.request | |
import lxml.html | |
from lxml import etree | |
import re | |
import os.path | |
# 変数宣言 | |
cnt = 5 #メッセージ取得回数 | |
message = [] #取得したメッセージを格納する配列 | |
str_date = [] #日付+時刻 | |
str_day = [] #日付 | |
str_time = [] #時刻 | |
str_mente =[] | |
# urlの指定 | |
url = 'https://jp.misumi-ec.com/' | |
# メンテ中かを確認 | |
page_status = requests.get(url) | |
print(page_status.status_code) | |
if page_status.status_code == 200 : | |
# ページの内容取得 | |
response = urllib.request.urlopen(url=url) | |
html = lxml.html.fromstring(response.read()) | |
# メッセージを順番に取得 | |
i = 1 | |
mescnt = 0 | |
for i in range(1,cnt): | |
headings = html.xpath("string(/html/body/div[1]/div[3]/div[1]/div[1]/div/ul/li[" + str(i) + "])") #動いた | |
if [headings]!=['']: | |
message += [headings] | |
mescnt += 1 | |
j = 0 | |
# 取得したメッセージに対して文字列抽出 | |
for j in range(0,mescnt): | |
str_date = re.findall('\d{1,2}\/\d{1,2}\s\d{1,2}:\d{2}', message[j]) | |
str_day = re.findall('\d{1,2}\/\d{1,2}\s', message[j]) | |
str_time = re.findall('\d{1,2}:\d{2}', message[j]) | |
str_mente = re.findall('メンテナンス', message[j]) # => [] | |
print(j) | |
print(str_mente) | |
if str_mente != []: | |
if str_mente[0]=='メンテナンス': | |
break | |
else: | |
j += 1 | |
else: | |
print("q") | |
break | |
if str_mente != []: #メンテある | |
if len(str_day) == 1: | |
p = "curl -X POST -H \"Content-Type: application/json\" -d \'{\"value1\":\" #ミスミメンテ \",\"value2\":\"" +str_day[0]+str_time[0]+ "\",\"value3\":\"" +str_day[0]+str_time[1]+ "\"}\' https://maker.ifttt.com/trigger/app-name/with/key/Account-Goto=nO_mojireTu" | |
req = os.system(p) | |
print(req) | |
else: | |
p = "curl -X POST -H \"Content-Type: application/json\" -d \'{\"value1\":\" #ミスミメンテ \",\"value2\":\"" +str_day[0]+str_time[0]+ "\",\"value3\":\"" +str_day[1]+str_time[1]+ "\"}\' https://maker.ifttt.com/trigger/app-name/with/key/Account-Goto=nO_mojireTu" | |
req = os.system(p) | |
print(req) | |
else: #メンテない | |
ppp = "curl -X POST -H \"Content-Type: application/json\" -d \'{\"value1\":\"予定されたメンテナンスはないよ\",\"value2\":\"-\",\"value3\":\"-\"}\' https://maker.ifttt.com/trigger/app-name/with/key/Account-Goto=nO_mojireTu" | |
print("^-^") | |
req2 = os.system(ppp) | |
print(req2) | |
else: | |
print("メンテ中です") | |
p_now = "curl -X POST https://maker.ifttt.com/trigger/app-name/with/key/Account-Goto=nO_mojireTu" | |
req3 = os.system(p_now) | |
print(req3) | |
# https://maker.ifttt.com/trigger/app-name/with/key/Account-Goto=nO_mojireTu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment