init
This commit is contained in:
commit
8f18c88125
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
venv/
|
||||
.env
|
40
main.py
Normal file
40
main.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from dotenv import load_dotenv
|
||||
from apscheduler.schedulers.background import BlockingScheduler
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def get_price(company_code):
|
||||
url = f"https://finance.naver.com/item/main.nhn?code={company_code}"
|
||||
result = requests.get(url)
|
||||
bs_obj = BeautifulSoup(result.content, "html.parser")
|
||||
no_today = bs_obj.find("p", {"class": "no_today"})
|
||||
blind_now = no_today.find("span", {"class": "blind"})
|
||||
return blind_now.text
|
||||
|
||||
def postStatus():
|
||||
company_code = '005930'
|
||||
price = get_price(company_code).replace(",", "")
|
||||
status = ""
|
||||
|
||||
if int(price) >= 80000:
|
||||
status = f"현재 삼성전자의 주가는 {price}원 입니다.\n드디어 팔만전자를 달성했습니다!"
|
||||
else:
|
||||
delta_to_80000 = 80000 - int(price)
|
||||
status = f"현재 삼성전자의 주가는 {price}원 입니다.\n팔만전자까지 {delta_to_80000}원 남았습니다."
|
||||
|
||||
data={
|
||||
"i": os.getenv("ACCESS_TOKEN"),
|
||||
"text": status,
|
||||
"visibility": "public"
|
||||
}
|
||||
res = requests.post(f"https://{os.getenv('INSTANCE')}/api/notes/create", json=data)
|
||||
print(res.status_code, res.json())
|
||||
|
||||
if __name__ == "__main__":
|
||||
sched = BlockingScheduler()
|
||||
# sched.add_job(postStatus, "cron", hour="15", minute="8", id="job1")
|
||||
sched.add_job(postStatus, "cron", hour="10,12,16", id="job1")
|
||||
sched.start()
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
bs4
|
||||
requests
|
||||
python-dotenv
|
||||
apscheduler
|
Loading…
Reference in a new issue