5
5
import requests
6
6
import smtplib
7
7
8
- '''
8
+ '''
9
9
<===== IMPORTANT =====>
10
10
1. THIS WILL NOT WORK WHEN SENDING MAIL FROM GMAIL BECAUSE OF NEW GOOGLE SECURITY POLICIES.
11
11
2. BUT YOU CAN SEND MAIL FROM OUTLOOK OR ANY OTHER MAIL SERVICES WITHOUT ANY PROBLEM.
14
14
'''
15
15
16
16
# Add your Email ID & it's Password by which you are sending the email alert
17
- from_email = "<SENDER'S_EMAIL_ID>"
18
- from_email_password = "<SENDER'S_EMAIL_PASSWORD>"
19
- mail_port = 587
20
- mail_server = "smtp-mail.outlook.com"
17
+ from_email = "<SENDER'S_EMAIL_ID>"
18
+ from_email_password = "<SENDER'S_EMAIL_PASSWORD>"
19
+ mail_port = 587
20
+ mail_server = "smtp-mail.outlook.com"
21
21
22
22
# Add Email ID to whom you want to send the alert
23
- to_email = "RECEIVER'S_EMAIL_ID"
23
+ to_email = "RECEIVER'S_EMAIL_ID"
24
24
25
25
26
26
def check_price ():
27
- spot_name = input ("Input the crypto currency to get alerts (eg. BTCUSDT): " )
27
+ spot_name = input ("Input the crypto currency to get alerts (eg. BTCUSDT): " )
28
28
print ("1.If Price hits Above\n 2.If Price hits Below\n " )
29
- cpolarity = int (input ("Choose from 1 & 2: " ))
30
- trig_point = 1
31
- if cpolarity == 1 :
32
- trig_point = float (input ("Input the trigger price(dollar) above at which you want to recieve mail alert: " ))
29
+ cpolarity = int (input ("Choose from 1 & 2: " ))
30
+ trig_point = 1
31
+ if cpolarity == 1 :
32
+ trig_point = float (input ("Input the trigger price(dollar) above at which you want to recieve mail alert: " ))
33
33
else :
34
- trig_point = float (input ("Input the trigger price(dollar) below at which you want to recieve mail alert: " ))
34
+ trig_point = float (input ("Input the trigger price(dollar) below at which you want to recieve mail alert: " ))
35
35
36
36
def send_mail ():
37
37
server = smtplib .SMTP (mail_server , mail_port )
@@ -41,40 +41,41 @@ def send_mail():
41
41
server .login (from_email , from_email_password )
42
42
subject = f"{ spot_name .upper ()} EXCHANGE RATE"
43
43
44
- if cpolarity == 1 :
44
+ if cpolarity == 1 :
45
45
body = f"{ spot_name .upper ()} Exchange is now above ${ trig_point } : Current Exchange Rate: ${ lprice } ."
46
46
else :
47
47
body = f"{ spot_name .upper ()} Exchange is now below ${ trig_point } : Current Exchange Rate: ${ lprice } ."
48
-
48
+
49
49
msg = f'''Subject: { subject } \n
50
50
To: { "" .join (to_email )} \n
51
51
{ body } '''
52
-
52
+
53
53
server .sendmail (from_email , to_email , msg .encode ("utf8" ))
54
-
54
+
55
55
print ("Alert! The E-mail has been sent!" )
56
56
server .quit ()
57
57
58
58
while True :
59
59
Url = "https://api.binance.com/api/v3/ticker/24hr"
60
60
r = requests .get (Url )
61
61
json_list = r .json ()
62
- cryptoname = {}
63
- lprice = 0
62
+ cryptoname = {}
63
+ lprice = 0
64
64
for i in range (len (json_list )):
65
- if json_list [i ]["symbol" ]== spot_name .upper ():
66
- cryptoname = json_list [i ]
65
+ if json_list [i ]["symbol" ] == spot_name .upper ():
66
+ cryptoname = json_list [i ]
67
67
try :
68
- lprice = float (cryptoname ["lastPrice" ])
68
+ lprice = float (cryptoname ["lastPrice" ])
69
69
print (lprice )
70
70
except :
71
71
print ("This Exchange is not available." )
72
72
73
- if lprice >= trig_point and cpolarity == 1 :
73
+ if lprice >= trig_point and cpolarity == 1 :
74
74
send_mail ()
75
75
exit ()
76
- if lprice <= trig_point and cpolarity == 2 :
76
+ if lprice <= trig_point and cpolarity == 2 :
77
77
send_mail ()
78
78
exit ()
79
79
80
+
80
81
check_price ()
0 commit comments