diff options
-rw-r--r-- | main.py | 88 |
1 files changed, 50 insertions, 38 deletions
@@ -1,11 +1,12 @@ import requests import smtplib import json +import websocket import time import sys import schedule -def price(): +def price(coin_ids): url = "https://api.coingecko.com/api/v3/coins/markets" params = { 'vs_currency': 'USD', @@ -18,47 +19,58 @@ def price(): response = requests.get(url, params=params) data = response.json() - btc_price = data[0]['current_price'] - return btc_price - -def email(btc): - # change the email address or create a email.txt file and put your email there - with open('email.txt', 'r') as file: - lines = [line.strip() for line in file] - - for line in lines: - sender_email = line - - # change the email address or create a pass.txt file and put your email password there - with open('pass.txt', 'r') as file: - lines = [line.strip() for line in file] - - for line in lines: - sender_password = line + btc_price = {} + for coin in data: + coin_id = coin['id'] + if coin_id in coin_ids: + btc_price[coin_id] = coin['current_price'] - # change your email to something else the alert will be send to there - receiver_email = "biswa@dmc.chat" - - subject = "BTC Price Alert" - body = f"The current price of BTC is {btc} USD. Time to make a move!" - - message = f"Subject: {subject}\n\n{body}" - - # change the mail.pissmail.com to the email provider you use - with smtplib.SMTP("mail.pissmail.com", 587) as server: - server.starttls() - server.login(sender_email, sender_password) - server.sendmail(sender_email, receiver_email, message) + return btc_price -def check(): - btc_price = price() - alert = int(input("enter the alert number you want: ")) +selected_coins = ['bitcoin', 'ethereum'] +btc_price = price(selected_coins) - if btc_price > alert: - email(btc_price) - print(f"Alert! BTC price is {btc_price} USD. Email sent.") +for coin, price in btc_price.items(): + print(f"{coin.capitalize()}: ${price}") -check() +#def email(btc): +# # change the email address or create a email.txt file and put your email there +# with open('email.txt', 'r') as file: +# lines = [line.strip() for line in file] +# +# for line in lines: +# sender_email = line +# +# # change the email address or create a pass.txt file and put your email password there +# with open('pass.txt', 'r') as file: +# lines = [line.strip() for line in file] +# +# for line in lines: +# sender_password = line +# +# # change your email to something else the alert will be send to there +# receiver_email = "biswa@dmc.chat" +# +# subject = "BTC Price Alert" +# body = f"The current price of BTC is {btc} USD. Time to make a move!" +# +# message = f"Subject: {subject}\n\n{body}" +# +# # change the mail.pissmail.com to the email provider you use +# with smtplib.SMTP("mail.pissmail.com", 587) as server: +# server.starttls() +# server.login(sender_email, sender_password) +# server.sendmail(sender_email, receiver_email, message) +# +#def check(): +# btc_price = price() +# alert = int(input("enter the alert number you want: ")) +# +# if btc_price > alert: +# email(btc_price) +# print(f"Alert! BTC price is {btc_price} USD. Email sent.") +# +#check() # schedule.every().hour.do(check) # while True: |