Skip to content

Instantly share code, notes, and snippets.

@buddypia
Created December 8, 2021 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buddypia/0b50deca6574fb206b2202ef9a9609db to your computer and use it in GitHub Desktop.
Save buddypia/0b50deca6574fb206b2202ef9a9609db to your computer and use it in GitHub Desktop.
Uniqloでエアリズムマスクが購入可能かどうかチェックするスクリプト(Mac用、購入可能通知)
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