Skip to content

Instantly share code, notes, and snippets.

💭
Teaching some Python

Mindy McAdams macloo

💭
Teaching some Python
Block or report user

Report or block macloo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@macloo
macloo / sqlite_first.py
Created Sep 10, 2019
Basic Python 3 for a SQLite db
View sqlite_first.py
import sqlite3
# no need to pip-install; comes w/ Python 3
# from https://www.youtube.com/watch?v=o-vsdfCBpsU
# db connection
# it's fine if the db named here doesn't exist yet - will be created
conn = sqlite3.connect('tutorial.db')
# define cursor
@macloo
macloo / percentiles.py
Created Sep 9, 2019
Some lists and stuff
View percentiles.py
percentiles = [10, 20, 30, 40, 50, 60 ,70, 80, 90]
all_scores = [44, 49, 54, 56, 62, 66, 67, 70, 72, 73, 73, 77, 80, 81, 83, 85, 85, 85, 89, 90, 96]
percentiles_with_scores = {k: [] for k in percentiles}
score_percentiles = tuple(zip(np.percentile(all_scores, percentiles), percentiles))
# let's see what's what
print("Tuples:")
print(score_percentiles)
print("The dictionary:")
@macloo
macloo / function_example.py
Created Sep 2, 2019
A short function lesson for beginners
View function_example.py
# To define a function, you write something in this pattern:
def name_of_function(arg1, arg2):
instructions
instructions
instructions
...
return something
# the number of arguments in parentheses may be none, or one, or any number
@macloo
macloo / d3_first_svg.html
Last active Jul 31, 2019
D3 lesson from FCC No. 10: Learn About SVG in D3 and No. 11: Display Shapes with SVG
View d3_first_svg.html
<style>
svg {
background-color: pink;
}
</style>
<body>
<script>
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
const w = 500;
@macloo
macloo / d3_simple_bar.html
Created Jul 31, 2019
From FCC D3 lessons, No. 8: Update the Height of an Element Dynamically
View d3_simple_bar.html
<style>
.bar {
width: 25px;
height: 100px;
display: inline-block;
background-color: blue;
/* extra style */
margin-right: 5px;
}
</style>
@macloo
macloo / make_list_from_file.py
Created Apr 16, 2019
Take a list of state abbreviations in a text file and put them into a Python list
View make_list_from_file.py
# copy a column from a table into a plain-text file in Atom, save it
# mine is named states.txt
# here's how to get each line in that file into Python as a list of items
myfile = open('states.txt')
states_raw = myfile.readlines()
# now states_raw holds a list made from lines in states.txt
myfile.close()
@macloo
macloo / romy_scrape1.py
Last active Apr 12, 2019
Example of stripping and splitting text
View romy_scrape1.py
from bs4 import BeautifulSoup
import requests
url = 'http://whc.unesco.org/en/list/937'
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
# <div class="alternate">
box = soup.find( "div", {"class":"alternate"} )
# print(box)
@macloo
macloo / headless_selenium.py
Last active Apr 9, 2019
Run Chrome headless with Selenium
View headless_selenium.py
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
chrome_options = Options()
chrome_options.add_argument("--headless")
# fill in your own path to installed chromedriver
driver = webdriver.Chrome(executable_path='/Users/dirname/dirname/dirname//chromedriver',
options=chrome_options)
@macloo
macloo / get_wiki_extract.py
Last active Apr 7, 2019
Use Python Wikipedia-API to get text summary for any subject in a list of subjects
View get_wiki_extract.py
"""
Requires Wikipedia-API 0.5.1 or greater - and Python 3
https://pypi.org/project/Wikipedia-API/
"""
import wikipediaapi
w = wikipediaapi.Wikipedia('en')
p = w.page('N._K._Jemisin')
@macloo
macloo / get_all_agency_urls2.py
Created Apr 1, 2019
For Sarah April 2019 - part 2
View get_all_agency_urls2.py
from urllib.request import urlopen
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import csv
driver = webdriver.Chrome('/Users/mcadams/Documents/python/scraping2019/chromedriver')
# testing the 'C' page only
driver.get('https://www.usa.gov/federal-agencies/c')
You can’t perform that action at this time.