Skip to content

Instantly share code, notes, and snippets.

View macloo's full-sized avatar
💭
Teaching some Python

Mindy McAdams macloo

💭
Teaching some Python
View GitHub Profile
@macloo
macloo / malaysia_UN.txt
Last active February 13, 2020 18:58
Data obtained by scraping UN Member Data page
Malaysia
17-09-57
http://www.un.int/malaysia/
313 East 43rd Street, New York, NY 10017
(212) 986-6310
http://data.un.org/CountryProfile.aspx?crName=Malaysia
The Federation of Malaya joined the United Nations on 17 September 1957. On 16 September 1963, its name was changed to Malaysia, following the admission to the new federation of Singapore, Sabah (North Borneo) and Sarawak. Singapore became an independent State on 9 August 1965 and a Member of the United Nations on 21 September 1965.
.
// this function has no parameters/arguments and does not return anything
function aboutMe() {
var sentence1 = name + " has lived in Florida for " + yearsLivedInFlorida + " years. ";
// test for true value
if (floridaNative) {
var sentence2 = name + " is a native of Florida. ";
} else {
var sentence2 = name + " is not a native of Florida. ";
}
var sentence3 = "Besides Gainesville, " + name + " has lived in " + citiesLivedIn.length + " cities.";
@macloo
macloo / .htaccess
Last active August 2, 2017 13:27
An .htaccess file for Dreamhost sites
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@macloo
macloo / write_db.php
Created July 12, 2017 21:17
Two files to write from an HTML form to a MySQL database
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<title> Write to the Shoutbox DB </title>
<link rel="stylesheet" href="css/main.css">
<style>
li { padding-bottom: 1em; }
</style>
@macloo
macloo / jabberwocky.txt
Created June 1, 2017 15:24
Plain text file for testing file operations
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
"Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!"
@macloo
macloo / individual_pages.py
Last active April 26, 2017 19:58
Scrape detail pages
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import time
import csv
hdr = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8,it;q=0.6',
@macloo
macloo / df.py
Created April 26, 2017 15:40
Scraper with sleep
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import time
hdr = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
@macloo
macloo / vv_dogfood_3.py
Created April 25, 2017 01:03
Scraping script
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import time
hdr = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
@macloo
macloo / partial_pf.py
Created April 24, 2017 18:55
Scraping example
def get_ruling_details(bsObj):
# fudging this because we are only doing one rep for now
repname = "Matt Gaetz"
rulings = bsObj.findAll("span", {"class":"chartlist__count"})
row = []
row.append(repname)
# create regex expression to get only the number - save as exp
exp = re.compile('^(\d+)')
for ruling in rulings:
# get the regex-matching string out of a ruling
@macloo
macloo / ha_loop.html
Created April 23, 2017 01:57
Example of Jinja2 loop
<ul>
{% for item in verse_info %}
<li>{{ item.verse }} {{ item.book }}</li>
{% endfor %}
</ul>