


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Files to submit: hw8.py Functions to include in hw8.py:
Use the examples from class of grabbing data from the internet (http://www- static.cc.gatech.edu/classes/AY2008/cs1301_spring/notes/readTimeFromURL.py) to write a method called getHumidity which takes in no parameters. Grab the humidity from this link through weather.com: http://www.weather.com/outlook/travel/businesstraveler/local/30309?lswe=30309&lwsa=Weath er36HourBusinessTravelerCommand&from=whatwhere Remember that viewing the source html of the page will be helpful to identify where the humidity is on the page. Return the humidity. Important notes: you will need to import urllib2 and be connected to the internet for this function to work. Sample Output:
>>> getHumidity() 'The humidity is: 26'
Write a function, avgNums that takes in a file as a parameter and averages the numbers contained in that file. Your function must average the numbers from the file, and the file will have exactly one number per line. Average these numbers and return the average. You will need to open the file, read the lines from it, put the data into something like an array and then close your file. Change the numbers in the provided file to test your code. Note that an extra carriage return after the last number could cause some trouble—you do not need to handle this case. Sample Output: >>> avgNums("/Users/PythonWarrior/Desktop/nums.txt") 'The average of the numbers in the file is 2.20' More information: http://www-static.cc.gatech.edu/classes/AY2008/cs1301_spring/notes/readFile.py You may find the readlines and split built-in methods to be helpful.
Write a function, makeImageFolder that takes in a path as a parameter. This function will go through the files in a folder and if it is an image (.jpg, .JPG, .png, .PNG or .gif, .GIF), copy it into a new folder called “Images.” NOTES: Don't worry about recursing through folders. In order to make a Directory for each file type use the os.mkdir(pathToNewDir) method You will need to copy the files. This requires another library that you haven’t used before, shutil, This library provides many operating system functions for copying, moving, renaming, and many other things you can do from the command line. It is also designed to work with any Operating System (Windows, Linux, OSX, even FreeBSD)
In this final part of the homework, you are going to use Python to automatically generate a web page version of a photo album. Don't get too scared—it’s not as hard as it sounds. After all a HTML web page is just text, and you are all masters at dealing with strings.
If you need help, be sure to come to office hours. Good Luck! Written by Matt Ruge and Beth York, Spring 2008