100 Days of Python: Days 31-35

Day 31

  • Capstone project day – Flash Cards (using tkinter) for learning most frequently used words in any language.
  • Built app GUI without walkthrough guide.
  • Used Pandas to convert csv of French -> English translations
  • Added logic to show target language for 3 seconds before flipping card to show English.
  • Used Pandas again to establish a CSV of unlearned words.
  • Used Try / Except to use the saved user words-to-learn list (if it exists).  If the file doesn’t exist, a new file is established using all possible words-to-learn.
Why download Anki when you can spend several hours developing a knockoff with a fraction of the features?

Day 32

  • Introduced to smtplib module for Python.
  • Setup dummy accounts as sender / recipient.
  • Used Python to send email over SMTP (including StartTLS)
  • Learned how to import modules with aliases (e.g. import datetime as dt)
  • Introduced to datetime module
  • Discovered pythonanywhere, a service that hosts, schedules and executes Python apps in the cloud.
  • Apps Created
    • Quote of the Day Emailer – On a given weekday, the application will send a random motivational quote.  The datetime module checks the day to see if the rest of the code should be triggered.  The quote is pulled from a text file full of quotes.  Smtplib builds and sends the message
    • Birthday Emailer – Every day, the app checks a contacts list CSV to determine if any of them have a birthday today.  If so, the user is added to the queue.  The app then grabs a random birthday template email and uses mail-merge logic to substitute in the birthday celebrater’s name.   Finally, the app uses smtplib to send the email.
Nothing like a good dose of reasonless optimism.

Day 33

  • Introduced Application Programming Interface – In today’s lesson, it will be a method of having our application interact with an external data source
  • API is a “menu” of items that you can extract from the data source (like a kitchen).
  • API endpoint is typically a URL that is used for interacting with the API
  • API GET requests are often returned as JSON objects.  These return as minimally formatted data packages.
  • Made first API request for the ISS’s current location and received response code 200.
  • Response codes:
    • 404 – Doesn’t exist.
    • 1xx – Not final, processing still occurring
    • 2xx – Success
    • 3xx – Permission error
    • 4xx – You (the user) screwed up
    • 5xx – I (the server) screwed up
  • Reviewed raising exceptions for API calls.
  • Reviewed extracting JSON from API calls and pulling dictionary data from the JSON
  • Interacted with Kanye West quote API to pull random Kanye quotes.
  • Interacted with Sunrise / Sunset API to determine when the sun will set and rise at a given Latitude / Longitude.
  • Apps Created:
    • ISS Sky Checker – The app checks every seconds to determine if the sky is dark and if the present position of the ISS is within 5 degrees (lat and lng) of my position.  If both requirements are met, an email is sent to me to tell me to run outside and look for the ISS.  The first API used were a sunrise / sunset API that lets me know when the sun will rise and set at my coordinates to determine if it is presently dark.  The second API reported the current coordinates of the ISS.
Tracking the ISS is very cool, but I’ll have to keep the telescope ready – the station zooms across the sky at around 17,500 miles per hour.

Day 34

  • Reviewed project of the day – an update to the Day 17 quiz app, which will now include a GUI and use API requests to pull questions from the Trivia API.
  • Learned about HTML entities and how to “unescape” them.
  • Created Quizzler app GUI.
  • Added UI class to manage the app UI using Tkinter.
  • Learned how to pass entire objects as arguments.
  • Learned how to declare datatypes to reduce errors in code.
  • Made UI more responsive to user actions to improve the experience.
  • This project was much more of a walkthrough than a challenge, many new things were introduced, but most of the solution was directly dictated.
  • I think I’ll look back at this project as a key building block because of the complex concepts that were introduced, but there isn’t much of an “I made this” feeling due to the amount of handholding.
The Trivia app was another great experience for working with APIs.

Day 35

  • API Authentication introduced.
  • APIs with valuable data (or maintenance-demanding data) tend to charge for usage.
  • API providers track your usage through an API key (essentially a username / password)
  • Reviewed https://openweathermap.org/ API inventory and setup an account.
  • Made several API calls to pull different localized forecasting data
  • Reviewed the One Call API and learned how to pull hourly forecasts and access specific data points for each forecasted hour.
  • Used Twilio API to send text message notification of rain forecast.
  • Hosted app in PythonAnywhere so that it may run in the cloud on a daily schedule.
  • Brief overview of environment variables
  • Used to separate sensitive data (e.g. keys) from the rest of the code.
  • Use of env variables allows your code to remain sanitized while living in public spaces (such as GitHub)
An app to make Ollie Williams proud.
Tagged in:,

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *