Skip to content

Instantly share code, notes, and snippets.

View send_ebook_codes.py
# be sure to enable less secure apps in gmail
import smtplib
import ssl
from email.mime.text import MIMEText
def send_gmail(sender, password, receiver, subject, body):
"""Prepare and send a nicely formatted Gmail"""
msg = MIMEText(body)
msg["Subject"] = subject
@AO8
AO8 / covid19.py
Last active Aug 11, 2020
Daily Coronavirus data update (global and WA state) with Python 3, requests, and beautifulsoup.
View covid19.py
# Check out https://ncov2019.live/data by Avi Schiffmann
# as featured in the Seattle Times at:
# https://www.seattletimes.com/seattle-news/education/qa-avi-schiffmann-the-washington-state-teen-behind-a-coronavirus-website-with-millions-of-views/
from email.mime.text import MIMEText
import smtplib
import ssl
import sys
import stdiomask
from bs4 import BeautifulSoup
@AO8
AO8 / dynamic_dice_roller.py
Last active Feb 7, 2020
Dynamic dice roll visualizer with Python 3 and Matplotlib.
View dynamic_dice_roller.py
import datetime
import random
import sys
from matplotlib import animation
import matplotlib.pyplot as plt
import seaborn as sns
def update(frame_number, rolls, faces, frequencies):
random.seed(datetime.datetime.now())
@AO8
AO8 / language_analyzer.py
Last active Jan 23, 2020
Python text analyzer using TextBlob and Textatistic.
View language_analyzer.py
import nltk
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
from textatistic import Textatistic
# This corpus is required for the Naive Bayes Analyzer
nltk.download("movie_reviews")
def main():
user_text = get_user_text()
@AO8
AO8 / check_weather.py
Last active Dec 18, 2019
Check the weather with Python 3 and the Open Weather dot Org API.
View check_weather.py
# explore the Open Weather dot Org API at: https://openweathermap.org/api
from datetime import datetime
import requests
def main():
# app_id will be specific to personal Open Weather acccount, 60 API calls per hour max
APP_ID = "#YourAppId"
# get zip code from user
zip_code = input("Enter a 5-digit, US zip code: ").strip()
@AO8
AO8 / profiler.py
Created Nov 8, 2019
A simple profiling example with the timeit module.
View profiler.py
import random
import timeit
TAX_RATE = .08
txns = [random.randrange(100) for _ in range(10000000)]
def get_price(txn):
return txn * (1 + TAX_RATE)
def get_prices_with_map():
@AO8
AO8 / countdown.py
Created Nov 1, 2019
A simple Python countdown clock.
View countdown.py
import sys
from time import sleep
def countdown(seconds):
while seconds > -1:
mins, secs = divmod(seconds, 60)
formatted_time = f"{mins:02d}:{secs:02d}"
if seconds > 3:
print(formatted_time, end="\r")
else:
@AO8
AO8 / sentiment_analyzer.py
Created Oct 30, 2019
This tiny Python app, powered by TextBlob, quickly measures the polarity and subjectiviy of a piece of text.
View sentiment_analyzer.py
# This Python program quickly measures the polarity and subjectivity of a piece of text.
from time import sleep
from textblob import TextBlob
def print_header():
print("*"*67)
print("PYTHON SENTIMENT TESTER (Powered by TextBlob)")
print()
print("POLARITY:")
@AO8
AO8 / secret_santa_pairing_program.py
Last active Oct 30, 2019
Create random Secret Santa gift-giving assignments at the click of a button with Python 3.
View secret_santa_pairing_program.py
# Step 1: Set up a Google form that collects First Name, Last Name, and Email Address from participants
# Step 2: Once all participants have completed the form, export it as a CSV file and store it in the same directory as this program
# Step 3: Run the program to create random Secret Santa gift-giving assignments so that each participant is paired with a different participant without duplication or anyone being left out
import csv
import datetime
import random
def main():
participants = get_participants_from_csv("test_file.csv")
@AO8
AO8 / grade_multi_plot.py
Last active Mar 29, 2019
Plot multiple subplots within a single figure to visualize the shape of grade distribution in various IT courses with Python 3 and Matplotlib.
View grade_multi_plot.py
# Corresponding CSV files exported from local SQL Engine.
import csv
from collections import Counter
import matplotlib.pyplot as plt
grades_102 = []
grades_201 = []
grades_206 = []
grades_207 = []
You can’t perform that action at this time.