aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
blob: 771a8f5e0eeb04d6155b59b5679ebc7f060d599c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import requests
import smtplib
import json
import websocket
import time
import sys
import schedule

def price(coin_ids):
    url = "https://api.coingecko.com/api/v3/coins/markets"
    params = {
        'vs_currency': 'USD',
        'order': 'market_cap_desc',
        'per_page': 100,
        'page': 1,
        'sparkline': False
    }

    response = requests.get(url, params=params)
    data = response.json()

    btc_price = {}
    for coin in data:
        coin_id = coin['id']
        if coin_id in coin_ids:
            btc_price[coin_id] = coin['current_price']
    return btc_price

# for multiple input
# user_input = input("Enter the coin IDs (comma-separated) you want to get prices for: ")
# selected_coins = [coin.strip().lower() for coin in user_input.split(',')]

selected_coins = input("enter the coin you want to view: ").lower()
btc_price = price(selected_coins)

for coin, price in btc_price.items():
    print(f"{coin.capitalize()}: ${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

    # change your email to something else the alert will be send to there
    receiver_email = "biswa@dmc.chat"

    subject = "Crypto Price Alert"
    body = f"The current price of {coin.capitalize()} 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.")

# you can comment below code and call the check() function to check everything is working smoothly or not
# check()
schedule.every().hour.do(check)

while True:
    schedule.run_pending()
    time.sleep(1)