commit 8f18c88125244822bd1061193d71d5bf790d1e64 Author: sunwoo1524 Date: Tue Feb 6 15:10:56 2024 +0900 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d558a03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/ +.env \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..419b908 --- /dev/null +++ b/main.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2cef344 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +bs4 +requests +python-dotenv +apscheduler \ No newline at end of file