Skip to content

Instantly share code, notes, and snippets.

@tookdes
Created April 27, 2018 12:28
Show Gist options
  • Select an option

  • Save tookdes/a0d58c181c92e55248700865975ebcf3 to your computer and use it in GitHub Desktop.

Select an option

Save tookdes/a0d58c181c92e55248700865975ebcf3 to your computer and use it in GitHub Desktop.
Get BitCoin Price and send it to your WeChat by ServerChan.
import requests
import time
import datetime
btc_price_api_url = 'https://api.coinmarketcap.com/v1/ticker/bitcoin/'
sc_url = "https://sc.ftqq.com/yourkey.send"
def get_latest_bitcoin_price():
response = requests.get(btc_price_api_url)
response_json = response.json()
return float(response_json[0]['price_usd']) # Convert the price to a floating point number
def sendSC(content):
Msg = {'text':'BTC Price', 'desp': '$'+content}
requests.get(sc_url, params=Msg)
def check_price():
now = datetime.datetime.now()
price = get_latest_bitcoin_price()
if price < 6300 or price > 7800:#CHANGE IT AS YOU LIKE
sendSC(price)
if now.hour==5 and now.minute==10:
sendSC(str(price))
if __name__ == "__main__":
while True:
check_price()
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment