Skip to content

Instantly share code, notes, and snippets.

@IT102Gists
IT102Gists / get_chuck_norris_joke.py
Last active April 17, 2022 08:09
Fetch a random joke from the Internet Chuck Norris Database (ICNDb) with Python 3 and Requests.
# Learn more about the ICNDb API at: http://www.icndb.com/api/
# Learn more about the Requests library at: http://docs.python-requests.org/en/master/
import requests
def get_joke():
"""fetches and prints a random joke"""
url = "http://api.icndb.com/jokes/random"
resp = requests.get(url)
data = resp.json()
@IT102Gists
IT102Gists / secret_santa.py
Created November 21, 2018 18:00
Remove the hassle from making Secret Santa gift giving assignments with Python 3. This short program uses Standard Library modules like csv, random, and smtplib to read a file, create random Secret Santa assignments, then prepare & send email notifications to each participant.
# To start, set up a Google form that collects
# first name, last name, and email address from participants,
# then export as a CSV file and store it in the same
# directory as this program
# also, enable less secure apps in gmail before running
# https://support.google.com/accounts/answer/6010255?hl=en
import csv
import smtplib
from random import shuffle
@IT102Gists
IT102Gists / pet_license_analyzer.py
Last active October 24, 2018 17:44
Python CodeAlong: Use Python to analyze pet license data from the City of Seattle.
# pet license csv file available at:
# https://data.seattle.gov/Community/Seattle-Pet-Licenses/jguv-t9rb
# data provided by City of Seattle Department of Finance and
# Administrative Services
import csv
# row 0 = license date
# row 1 = license num
# row 2 = name
@IT102Gists
IT102Gists / ask_zen_of_python.py
Created October 17, 2018 16:18
Python CodeAlong: an intro to the Zen of Python and webscraping with Beautiful Soup.
# standard library
import random
from urllib.request import urlopen
# third-party
from bs4 import BeautifulSoup
# make an HTTP request to get the Zen of Python
url = "https://www.python.org/dev/peps/pep-0020/"
html = urlopen(url)
@IT102Gists
IT102Gists / astros.py
Last active October 17, 2018 15:43
Python CodeAlong: see how many people are in space *right now* with Python.
# Python's built-in module for encoding and decoding JSON data
import json
# Python's built-in module for opening and reading URLs
from urllib.request import urlopen
# this api returns the current number of people in space
url = "http://api.open-notify.org/astros.json"
# send a request and get a JSON response
resp = urlopen(url)
@IT102Gists
IT102Gists / isbn_lookup.py
Last active September 24, 2023 16:18
Python CodeAlong: use the Google Books API to retrieve and display information about a book.
# Python's built-in module for encoding and decoding JSON data
import json
# Python's built-in module for opening and reading URLs
from urllib.request import urlopen
# sample ISBN for testing: 1593276036
while True:
# create getting started variables