用Line 看股票就不會被抓到上班看股票~~~~~~~

 

由Python 軟體搭配Line ,選擇你想要看的股票,再來間隔多久進行報價到Line 。

這樣你不用打開股票軟體都可以知道現在股票價位~~

 

Python 程式碼如下

import twstock
import requests
import schedule
import time
import datetime
 
def get_two_float(f_str, n):
    a, b, c = f_str.partition('.')
    c = c[:n]
    return ".".join([a, c])
 
def sendToLine():
    stock2330 = twstock.realtime.get('6244')
    low2330 = stock2330['realtime']['low']
    high2330 = stock2330['realtime']['high']
    ltr2330 = stock2330['realtime']['latest_trade_price']
    open2330 = stock2330['realtime']['open']
   
    msg2330=(f' \n 茂迪 6244 \n 最低 {get_two_float(low2330, 2)} || 最高 {get_two_float(high2330, 2)} \n 開盤 {get_two_float(open2330, 2)} || 現價 {get_two_float(ltr2330, 2)} \n )
   
    url = "https://notify-api.line.me/api/notify"
    payload={'message':{msg2330}}
    headers = {'Authorization': 'Bearer ' + '輸入Line 權杖號碼'}
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)
 
 
schedule.every(10).minutes.do(sendToLine)
while True:
    now = datetime.datetime.now()
    start_time = datetime.datetime(now.year, now.month, now.day, 9, 0, 0)
    end_time = datetime.datetime(now.year, now.month, now.day, 13, 45, 0)
 
    if start_time <= now <= end_time:
        # 在指定時間內執行程式
        # your code here
    #   schedule.every(10).minutes.do(sendToLine)
     
      schedule.run_pending()
      time.sleep(10)

 

這個程式可以只在09:00~13:45 時間內進行報價

 

請注意~~Line 權杖每日最高只有1000則可以發送~~~

 

 

 

 

 

 

 

arrow
arrow
    文章標籤
    Line 股票 報價
    全站熱搜
    創作者介紹
    創作者 bobte1688 的頭像
    bobte1688

    遊玩的天地

    bobte1688 發表在 痞客邦 留言(0) 人氣()