This commit is contained in:
sunwoo1524 2024-02-06 15:10:56 +09:00
commit 8f18c88125
3 changed files with 46 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
venv/
.env

40
main.py Normal file
View 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
View file

@ -0,0 +1,4 @@
bs4
requests
python-dotenv
apscheduler