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:
Sorry I missed this presentation on #PYPT. I did not make it to the evening show.
Very cool stuff. I am also learning coding in Python. Even this old dog can learn new tricks!
No problem, learning is how this old dog keeps his mind fresh.
Keep going!
Good to see you on PYPT, one of my New Year's Resolutions is to learn a few coding languages.
@alliedforces curate
Keep up the great work and join us in The Castle sometime!
The #spreadlovenotwar curation campaign is under the guidance of witnesses @enginewitty and @untersatz.
Thanks, I have written basic code in half a dozen languages over the years, but Python is structured the most like talking, which makes it easy to learn and write. Big bonus for me is a lot of the backend stuff on STEEM uses Python so I might be able to learn how do do more here.
Thanks also for the @alliedforces curate.
Sweet, I need some easy buttons when I hunker down and start my own courses :P
I want to learn how to code in python it's so hard to me that language I think ehhe because we didn't use this programming language in previous year we've use java c++ and until now I'm learning hehe for these programming language