50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import time
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
from datetime import datetime
|
|
from stock.util.SlackBot import SlackBot
|
|
|
|
class HTS_Alert :
|
|
slackBot = None
|
|
|
|
def __init__(self):
|
|
self.slackBot = SlackBot()
|
|
return
|
|
|
|
def checkPrice(self, code):
|
|
code_index = 0
|
|
PERCENT = ["50%", "50%"]
|
|
CHECK_PRICE = [2565, 2422]
|
|
|
|
THIS_TIME = datetime.now()
|
|
today = datetime.today().strftime('%Y%m%d')
|
|
while datetime.strptime(today + " 080000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
|
|
url = 'https://finance.naver.com/item/main.naver?code={code}'.format(code=code.strip())
|
|
res = requests.get(url)
|
|
|
|
html = res.text
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
post = soup.select_one('#chart_area > .rate_info > .today > .no_today > em')
|
|
arr = post.text.split("\n")
|
|
c_price = int(arr[1].replace(',', ''))
|
|
|
|
if c_price < CHECK_PRICE[code_index]:
|
|
self.slackBot.sendMsg(code + " " + str(CHECK_PRICE[code_index]) + " " + PERCENT[code_index] + "를 파세요...")
|
|
code_index += 1
|
|
|
|
if code_index > len(CHECK_PRICE):
|
|
break
|
|
|
|
time.sleep(60)
|
|
THIS_TIME = datetime.now()
|
|
return
|
|
|
|
if __name__ == "__main__":
|
|
hTS_Alert = HTS_Alert()
|
|
|
|
week = datetime.today().weekday()
|
|
if week in (0, 1, 2, 3, 4): # 0:월, 1:화, 2:수, 3:목, 4:금, 5:토, 6:일
|
|
|
|
post = hTS_Alert.checkPrice('252670')
|
|
|
|
print ("done...") |