Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Created July 20, 2016 03:39
Show Gist options
  • Save ShinJJang/fd044fafa046729670cd451344235291 to your computer and use it in GitHub Desktop.
Save ShinJJang/fd044fafa046729670cd451344235291 to your computer and use it in GitHub Desktop.
compuzone의 GTX 1080 재고를 확인합니다. 16개의 상품이 있는데, 품절이 아닌 것이 생기면 slack 메세지를 쏩니다.
# -*- coding: utf-8 -*-
#!/usr/bin/python
from bs4 import BeautifulSoup
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from apscheduler.schedulers.blocking import BlockingScheduler
from slackclient import SlackClient
slack_token = "your slack slack_token"
def request_1080_remains():
url = 'http://www.compuzone.co.kr/product/product_list.php'
# BigDivNo=4&MediumDivNo=1016&DivNo=2043&PreOrder=recommand&OrderType=3&OrderLinkType=&SChkMaker=&SChkBottom=384|22684|0,&MakerNo=&MidMakerNo=&stROW_CNT=40&DivProductKey=&stSKIN_TYPE=1&stPage=1
values = {"BigDivNo":4, "MediumDivNo":1016, "DivNo":2043, "PreOrder":"recommand", "OrderType":3, "SChkBottom":"384|22684|0,", "stROW_CNT":40, "stSKIN_TYPE":1, "stPage":1}
data = urlencode(values)
req = Request(url, data.encode('utf-8'))
response = urlopen(req)
result = response.read().decode('utf-8', 'ignore')
soup = BeautifulSoup(result, "html.parser")
count = len(soup.select('.width_list_list_btn img'))
print("현재 1080 품절 갯수 : %s" % count)
if count != 16:
send_alert(count)
def send_alert(count):
sc = SlackClient(slack_token)
msg = "GTX 1080 16개 품절 상품이 %s개로 변했다!!!" % count
sc.api_call(
"chat.postMessage", channel="#channel", text=msg,
username='이건 사야해', icon_emoji=':robot_face:'
)
if __name__ == "__main__":
sched = BlockingScheduler()
sched.add_job(request_1080_remains, 'interval', seconds = 30)
sched.start()
@ShinJJang
Copy link
Author

결과 화면 (메세지는 다릅니다)
2016-07-20 12 51 06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment