May-09-2020, 11:48 AM
Hey everyone!
It's been a week since I started making this script. The main idea was to make a script that will send a bitcoin price to my email every 30 minutes using an API.
I decided to make it two parts, and then combine it together. The first part of the price updates every 30 minutes was pretty easy to make. The second part with the email was a little bit harder, but I understood how it works anyways. When sending an email to myself with a simple message, everything seems to be working fine, but I just can't understand how do I send the price, because the way that I did it, makes it just send a blank email.
It's been a week since I started making this script. The main idea was to make a script that will send a bitcoin price to my email every 30 minutes using an API.
I decided to make it two parts, and then combine it together. The first part of the price updates every 30 minutes was pretty easy to make. The second part with the email was a little bit harder, but I understood how it works anyways. When sending an email to myself with a simple message, everything seems to be working fine, but I just can't understand how do I send the price, because the way that I did it, makes it just send a blank email.
import smtplib import time import datetime import requests email_sender_address = 'n/a' email_receiver_address = 'n/a' email_password = 'n/a' server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(email_sender_address, email_password) while True: response = requests.get('https://blockchain.info/ticker') if response.status_code == 200: data = response.json() now = datetime.datetime.now() message = ("price:%d" %(data["USD"]["last"])) server.sendmail(email_sender_address, email_receiver_address, message) time.sleep(1800)