Created
April 19, 2021 08:43
-
-
Save LordGhostX/662a8de910459495b1aa5ecba8027b9c to your computer and use it in GitHub Desktop.
Get Cryptocurrency prices straight to your Telegram account.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
from bs4 import BeautifulSoup | |
bot_token = "" | |
chat_id = "" | |
def get_coin_stats(coin): | |
r = requests.get(f"https://www.coingecko.com/en/coins/{coin.lower()}") | |
soup = BeautifulSoup(r.text, "html.parser") | |
price = soup.find("span", {"class": "no-wrap"}).text | |
candle_section = soup.find_all( | |
"div", {"class": "mt-1"})[2].find_all("div", {"mt-1"})[2].find_all("span") | |
low_price = candle_section[0].text | |
high_price = candle_section[1].text | |
change_pct = soup.find( | |
"span", {"class": "live-percent-change"}).text.strip() | |
return f"{coin.upper()} Stats\nPrice: {price}\nPrice Low: {low_price}\nPrice High: {high_price}\nChange %: {change_pct}\n\n" | |
def send_coin_prices(): | |
prices = get_coin_stats("shiba-inu") + get_coin_stats("xrp") | |
requests.get( | |
f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={prices}") | |
while True: | |
send_coin_prices() | |
time.sleep(60 * 60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment