Created
December 8, 2021 05:02
-
-
Save buddypia/0b50deca6574fb206b2202ef9a9609db to your computer and use it in GitHub Desktop.
Uniqloでエアリズムマスクが購入可能かどうかチェックするスクリプト(Mac用、購入可能通知)
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
import urllib.request #ライブラリをインポートします | |
from bs4 import BeautifulSoup | |
import threading | |
import os | |
class UniqloMask: | |
""" | |
Uniqloエアリズムマスクの購入ボタン監視のスクレイピングクラス | |
""" | |
def __init__(self, url): | |
self.url = url | |
def execute(self): | |
headers = { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0" } | |
request = urllib.request.Request(self.url, headers=headers) | |
html = urllib.request.urlopen(request) | |
if html.getcode() != 200: | |
print("html.getcode(): %d" % html.getcode()) | |
return | |
soup = BeautifulSoup(html, 'html.parser') | |
not_buyable_airism_button = soup.find('a', class_='fr-linkButton -black fr-sp-mt-l u-sp-mb-none fr-pc-mt-l js-trackEvent -disabled') | |
if not_buyable_airism_button == None: | |
print('エアリズムマスク買えるよん') | |
os.system("osascript -e 'display notification \"You may be able to buy an AIRism mask.\"'") | |
else: | |
print(not_buyable_airism_button.text.strip()) | |
return | |
def set_interval(func, sec): | |
def func_wrapper(): | |
set_interval(func, sec) | |
func() | |
t = threading.Timer(sec, func_wrapper) | |
t.start() | |
return t | |
uniqlo_mask = UniqloMask(url='https://www.uniqlo.com/jp/ja/contents/feature/airism-mask/') | |
uniqlo_mask.execute() | |
set_interval(uniqlo_mask.execute, 600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment