Docsity

CS 1301 Spring 2008 Homework 8: OS and File I/O, Assignments of Computer Science

Toggle sidebar
bg1
Homework 8 CS 1301 – Spring 2008 Page 1/4
CS 1301 – Spring 2008
Homework 8 – OS Triumphant Return
Due: Wednesday, April 2nd, 2008 at 11:55 PM EST
Files to submit: hw8.py
Functions to include in hw8.py:
1. getHumidity
2. avgNums
3. makeImageFolder
4. makePicAlbum
5. getImages
Parameters for functions will be noted in write-up below.
For Help:
T-Square Forums – see course syllabus for more detailed information
TA Helpdesk – schedule is posted on class website
Email TAs
Notes:
Think through the logic of each of the problems before you start coding anything
Don’t forget to include the required comments and collaboration statement (as outlined
on the course syllabus)
Do not wait until the last minute to do this assignment in case you run into problems
If you find an error in the homework assignment, let a TA know immediately
Part 1 – getHumidity
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:
pf3
pf4

Partial preview of the text

Download CS 1301 Spring 2008 Homework 8: OS and File I/O and more Assignments Computer Science in PDF only on Docsity!

CS 1301 – Spring 2008

Homework 8 – OS Triumphant Return

Due: Wednesday, April 2nd, 2008 at 11:55 PM EST

Files to submit: hw8.py Functions to include in hw8.py:

  1. getHumidity
  2. avgNums
  3. makeImageFolder
  4. makePicAlbum
  5. getImages Parameters for functions will be noted in write-up below. For Help:  T-Square Forums – see course syllabus for more detailed information  TA Helpdesk – schedule is posted on class website  Email TAs Notes:  Think through the logic of each of the problems before you start coding anything  Don’t forget to include the required comments and collaboration statement (as outlined on the course syllabus)  Do not wait until the last minute to do this assignment in case you run into problems  If you find an error in the homework assignment, let a TA know immediately

Part 1 – getHumidity

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'

Part 2 – Average the numbers in a file

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.

Part 3 – Make a folder of images

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)

  • http://docs.python.org/lib/module-shutil.html
  • you will need the following command (don't forget to import shutil) o shutil.copy(SourcePath, DestinationPath)

Part 4 – Make an HTML page of images

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