Class 14 — Friday, March 5
Web and CSV Chrestomathics
CVS Drugstore — Is not to be examined — CSV files yes
Look both ways
Agenda
- Chrestomathics
- CSV processing
Readability
- Recommended practices
Test 2
- Wednesday March 17
Downloads
- Download module url.py
- Check out its (documentation](http://www.cs.virginia.edu/~cs1112/modules/local/url/)
- Program weathering_heights.py
- Program csv_is_not_a_pharmacy.py
- Program where_is_it.py
To do
- Review artifacts
Program weathering_heights.py — you don't need a weather person to know which way the wind blows
- Makes use of module url.py to access a weather forecast for a user-specified zipcode by querying the forecast.weather.gov website
Insight by examples
- https://forecast.weather.gov/zipcity.php?inputstring=22903 (Charlottesville)
<!DOCTYPE html> <html class="no-js"> ...
<div class="row row-odd row-forecast"><div class="col-sm-2 forecast-label"><b>Today</b></div> <div class="col-sm-10 forecast-text"> Sunny, with a high near 48. Northwest wind around 11 mph, with gusts as high as 23 mph. </div> ...
</body> </html>
- https://forecast.weather.gov/zipcity.php?inputstring=14301 (Niagra Falls, NY)
<!DOCTYPE html> <html class="no-js"> ...
<div class="row row-odd row-forecast"><div class="col-sm-2 forecast-label"><b>Today</b></div> <div class="col-sm-10 forecast-text"> Sunny, with a high near 33. Breezy, with a west wind 18 to 21 mph, with gusts as high as 33 mph. </div> ...
</body> </html>
<!DOCTYPE html> <html class="no-js"> ...
<div class="row row-odd row-forecast"><div class="col-sm-2 forecast-label"><b>Today</b></div> <div class="col-sm-10 forecast-text"> Patchy blowing dust before 1pm. Partly sunny, with a high near 57. Windy, with a north wind 25 to 30 mph, with gusts as high as 45 mph. </div> ...
</body> </html>
Some program runs
Enter zipcode: 22903
Sunny, with a high near 48. Northwest wind around 11 mph, with gusts as high as 23 mph.
Enter zipcode: 14301
Sunny, with a high near 33. Breezy, with a west wind 18 to 21 mph, with gusts as high as 33 mph.
Enter zipcode: 79382
Patchy blowing dust before 1pm. Partly sunny, with a high near 57. Windy, with a north wind 25 to 30 mph, with gusts as high as 45 mph.
Algorithm
- Get access to url get web content capabilities
- Define helpful constants — base query, forecast delimiters, lengths of forecast delimiteres
- Get user zip code of interest
- Create the query link to get forecast from national weather service
- Get the contents of the page found at the forecast link
- Find indexes of query front and rear delimiters
- Find indexes of forecast front and rear
- Get the forecast substring from the page
- Print the forecast
Some more datasets
Location, Author, Max Height, Min Height
Narnia, Lewis, 4810, -10
Neverland, Milne, 426, -2
Oz, Baum, 1231, 679
Sleepy Hollow, Irving, 1629, 304
Stars Hollow, Sherman-Palladino, 725, 152
Toyland, MacDonough, 6187, 0
Wonderland, Carroll, 5895, -5
Country, Females, Males
Australia, 11175724, 11092660
Fiji, 421365, 439258
French Polynesia, 132082, 138682
New Caledonia, 125322, 125548
New Zealand, 2223281, 2144855
Papua New Guinea, 3359979, 3498287
Solomon Islands, 259909, 278239
Vanuatu, 117573, 122078
King City, CA, 36.21106, -121.05986
Fischer, TX, 29.960139, -98.21846
Alma, AR, 35.48891, -94.20897
Mount Moriah, MO, 40.30922, -93.794818
Sparkman, AR, 33.91855, -92.80484
Logansport, LA, 31.991863, -93.98356
...
Steeleville, IL, 38.002188, -89.66723
Underwood, IN, 38.603451, -85.76711
Caledonia, ND, 47.472415, -96.8887
Wales, WI, 43.002534, -88.37771
Greenwich, KS, 37.78335, -97.205419
Lansing, WV, 38.079509, -81.06238
Program csv_is_not_a_pharmacy.py — streamlining getting a dataset
- Makes use of module url.py
Some program runs
Enter name of dataset: oceania.csv
dataset:
Country, Females, Males
Australia, 11175724, 11092660
Fiji, 421365, 439258
French Polynesia, 132082, 138682
New Caledonia, 125322, 125548
New Zealand, 2223281, 2144855
Papua New Guinea, 3359979, 3498287
Solomon Islands, 259909, 278239
Vanuatu, 117573, 122078
header:
['Country', 'Females', 'Males']
data:
['Country', 'Females', 'Males']
['Australia', 11175724, 11092660]
['Fiji', 421365, 439258]
['French Polynesia', 132082, 138682]
['New Caledonia', 125322, 125548]
['New Zealand', 2223281, 2144855]
['Papua New Guinea', 3359979, 3498287]
['Solomon Islands', 259909, 278239]
['Vanuatu', 117573, 122078]
Enter name of dataset: elevations.csv
dataset:
Location, Author, Max Height, Min Height
Narnia, Lewis, 4810, -10
Neverland, Milne, 426, -2
Oz, Baum, 1231, 679
Sleepy Hollow, Irving, 1629, 304
Stars Hollow, Sherman-Palladino, 725, 152
Toyland, MacDonough, 6187, 0
Wonderland, Carroll, 5895, -5
header:
['Location', 'Author', 'Max Height', 'Min Height']
data:
['Narnia', 'Lewis', 4810, -10]
['Neverland', 'Milne', 426, -2]
['Oz', 'Baum', 1231, 679]
['Sleepy Hollow', 'Irving', 1629, 304]
['Stars Hollow', 'Sherman-Palladino', 725, 152]
['Toyland', 'MacDonough', 6187, 0]
['Wonderland', 'Carroll', 5895, -5]
Program where_is_it.py — where is it
- Determines a rough estimate of the center of continental USA by making use of CSV dataset usa-continental.csv
- Question
- How should we determine the estimate?
Lebanon, KS, 66952, 39°48′38″N 98°33′22″W
🦆 © 2022 Jim Cohoon | Resources from previous semesters are available. |