Day 10, I have added another API call to CoinGecko for SBD price and made a side track from Programming with Python | Python for Beginners
to learn a different way to store credentials outside of my python code. The Microsoft videos used the Python module dotenv, but I have learned how to use the Python module keyring which is more secure.
Here is the code from today's learning:
from datetime import datetime, timedelta
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
import time
import MySQLdb
import keyring
import logging
log = logging.getLogger("pylearn-day10")
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
filename='pylearn.log',
filemode='a')
log.info("Starting program")
utc_date = datetime.utcnow()
print('pylearn-day10 ' + str(utc_date) + ' UTC')
print()
print('Get current STEEM price from CoinGecko')
steemprice = cg.get_price(ids='steem', vs_currencies='usd')
print()
print('Display STEEM USD price returned')
print(steemprice['steem']['usd'])
print()
print('Get current SBD price from CoinGecko')
sbdprice = cg.get_price(ids='steem-dollars', vs_currencies='usd')
print()
print('Display SBD USD price returned')
print(sbdprice['steem-dollars']['usd'])
print()
print('Testing getting MySQL password from keyring secure database')
pidatapass = keyring.get_password('MySQL', 'pidata')
print()
querydatetime = datetime.now()
querydate = querydatetime.strftime("%Y-%m-%d")
print('get todays date' + querydate)
print()
print('Query database with retrieved password')
db = MySQLdb.connect("10.0.0.200", "pidata", pidatapass, "home_data")
cursor = db.cursor()
sqlcmd = "select min(temp) from temperatures where tempTime like '" + querydate + "%' and location like 'RearDeck';"
cursor.execute(sqlcmd)
row = cursor.fetchone()
print(" Min Temp " + str(row[0]))
And here is a screen capture of the output from the program: