aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-03-08 00:46:46 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-03-08 00:46:46 +0530
commitb73129ce2f8f3098953e94c37ce794f067f4f48d (patch)
tree50f026f268153f155f3b2dc82dce79534a74c9af
downloadcrypto-alert-b73129ce2f8f3098953e94c37ce794f067f4f48d.tar.gz
crypto-alert-b73129ce2f8f3098953e94c37ce794f067f4f48d.tar.bz2
crypto-alert-b73129ce2f8f3098953e94c37ce794f067f4f48d.zip
crypto alert
-rw-r--r--.gitignore1
-rw-r--r--main.py42
2 files changed, 43 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f7275bb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+venv/
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..7802d94
--- /dev/null
+++ b/main.py
@@ -0,0 +1,42 @@
+import requests
+import smtplib
+import json
+
+def price():
+ 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 = data[0]['current_price']
+ return btc_price
+
+def email(btc):
+ sender_email = "your mail address"
+ sender_password = "password"
+ receiver_email = "receiving email"
+
+ 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)
+
+btc_price = price()
+alert = 33000
+
+if btc_price == alert_threshold:
+ email(btc_price)
+ print(f"Alert! BTC price is {btc_price} USD. Email sent.")