Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Spring 2005 Homework 4 Questions

Ask questions about Homework 4 here.





I am trying to start this homework, but I am kinda lost. I know how to write a little HTML, but I am not sure how to input it through Python and write it into the index.html file.

You should review the lectures that dealt with importing OS. What you're going to need to do is create a file called index.html saving it in the inputted directory using the open method You will then create a string and add all the html and text you will need for the page to this string. Then you will write the string to the file, using the file.write(string) method. Creating this string is what the function will do. It will look in the inputted directory and add things to the string based on whether the current file it is looking at is a jpg file or a wav file. Review the function os.listdir to see how you should be doing this. If you are still confused, I recommend seing a TA at office hours. It's a lot easier to answer a broad question like this in person. Kelly Lyons

Does "half-size version" mean that both the height and width should be half size, or just the height?
Both. But if you just set just either width or height in the IMG tag, your browser automagically keeps the ratios.

How can we get just the first and last second of a sound?
You have to fidget with the getLength and getSamplingRate functions and do a little math.


I've wrote my code, but how do I make sure it works?
Run your program using a path to a folder with pictures and sounds in it. If everything works correctly an index.html file will be created in the folder with the pictures and sounds. Albert d'Heurle

The first part of the assignment says "given a folder"....so which folder are we to use? Mediasources????
I wouldn't suggest using the whole mediaSources folder. I would probably make a new folder somewhere that just has a few files, maybe 3 or 4 pictures, 3 or 4 sounds, and some other files just to make sure the code won't break with them. Amanda Bennett



do we write the code for the html page within the function makeLinksPage?
You write JES code that will generate the html page in the function. Kelly Lyons

when i open my index.html file through the internet, I get a page with a list of the files in my folder. Is this what I'm supposed to get?
You are supposed to be seeing the pictures from your folder (half sized) which will link to your full sized image, and text links for the sounds to the actual sound. If all you are getting is a list of files, then that is not correct. Kelly Lyons

I'm having trouble linking my thumbnails to their original size pictures... I know how to make pictures as links, but I just don't know what to put after a href="???

Scratch that! I figured it out!

When I view my webpage, I get little red x's and not actual pictures.
That means that in the HTML, the link to the picture is incorrect and the picture isn't where it says it is. View the source of the webpage and find where it defines what the path is and compare that to where the pictures actually are in your computer. These two need to be the same for you to see the pictures. Kelly Lyons

I can link to my pictures fine and they come up from the link correctly. How do I set the height to a picture to be 50%. I can manually set a value but I am not sure how to set one for a range of heights.
You will need to use the getWidth() function in JES to figure out how wide the image is, then divide by two to get the halfsize width. -Travis Shepherd


what do I type in the command area to run the program. I'm not entirely sure what needs to be loaded up down there first or put in as input.


Are we supposed to create the half-sized images in JES or html, it seems like it would be a lot easier to do the half-sizing in the html, inside of the image tag, but in order to make it work for any picture it seems like it needs to be in the JES code...I have been reviewing slides and the book and I am still a little bit confused how JES and html interact....
in HTML Amanda Bennett
HTML is simply a file with text in it. It just has to be correctly formatted text so that tags show up in the right place;things are in quotes when the should be;etc. JES interacts with the HTML by creating the text you will need in the html file and writing it to the file. Every time there is a .jpg file in your directory, JES should create an html tag (basically a string) that will correctly display a half-sized image link to the full sized image and then write that string to the index.html file. In this html tage, you want there to be a height = something section that will make the image half sized. With variable sized images, you of course cannot simply put a number there but if you knew the height of the image you could simply use whatever that is divided by 2. Think of functions in JES that are available to you that could do this. Kelly Lyons

where it says that the anchor for sounds should say "full" and "short," do we have to specify the name of the file for which the anchor is? otherwise we just get a list of the words "full" and "short" with no idea where they will lead us?
The anchor should read full_filename and short_filename. Kelly Lyons

How can I half size the picture inside of image tag?? Do use getHeight(file)/2 directly in it (it dose not work..) or do i need to call a jes function?
It may not be working becuase you can't get the height of a file. Try creating a picture from the file and using getHeight on the picture. Kelly Lyons


is a specified directory the only input we should have for the function? can we have some additional inputs?
The only input you need for this homework is a path to a directory. - Albert d'Heurle

if the original sound file is less than or equal to two seconds, do we still have to create a link to it? if so, what should we name it as? full_file? thanks
If the sound file is less than 2 seconds then you still have to create a link to it. You can name it full_file.wav. Albert d'Heurle


can you tell me what is wrong with my code?
samplesfile=open(directory+os.sep+"//index.html","wt")
it worked yesterday but it gives me an error message of "an attempt was make to call a function with a parameter of an invalid type. this means that you did someghing such as trying to pass a string to a method that is expecting an integer"!!!


nevermind... Got it!!!!

waht is wrong with
if getLength(sound)/getSamplingRate(sound)>=2 :
??
it keeps giving me an error message...
I'm not sure. When I run it, it works fine. What is the error message you are getting? That might help me figure out what is wrong. Kelly Lyons
I tried it in JESS and didn't get an error. what error are you seeing? Blair MacIntyre

how do i get the first and the last second of the sound? i tried the function kelly taught us this morning but it kept giving me different error messages. sometimes it's b/c the short file is too small and can take up all the samples and sometimes it just tells me there is 0 frames in the sample. thanks

sorry, i meant to say the short file is too small it CAN'T take up all the samples from the first and last seconds of the bigger(original) file
I would have to see your code to tell you what is wrong. If it's not able to take all the samples, then you are trying to copy too many samples into the sound. Check your for loop and make sure there is no +1 in your range. That tends to cause errors. Also, if you're getting errors that say there are no frames in the sample, it might have something to do with the sound it is trying to shorten. Make sure that isn't a corrupted sound. If you still have questions, feel free to ask in breakout tonight (if you are in Thursday breakout) or come see me or some other TA during office hours and we can look at your code and see what's wrong with it. Kelly Lyons

JES will not allow me to use any kind of previously established integer variable (i.e. halfWidth) within a string concatenation that creates the html. I can't figure out what's wrong. Could it be the quotes? I could have sworn that

width="'+halfWidth+'"

within the HTML string would just substitute the actual numerical width, halved, in the place of halfWidth, and make that part of the the HTML in the end. Any suggestions?

Try using str(halfWidth) this will convert the numeric integer into a text string... took me forever to figure that one out.- Adam Caskey


When I put if getLength(sound)getSamplingRate(sound2) into my code I get the message:
Filename C:\Documents and Settings\User\My Documents\JES Software\samples/Thumbs.db could not be read.
Are you sure it's a valid sound file?
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.

What's wrong with this?

It is trying to get the length of the Thumbs.db file which is not a sound. For this to work, it must be run only on files that end with .wav Use an if statement to decide if the given file is a .wav file before you try to get the length of the sound. Kelly Lyons

what's the problem if my entire page works right, but when I click on a sound link (short version or long version) and hit 'open' my windows media player gives me an error that says, "one or more codecs required to play the file could not be found"?

nevermind... the MediaSources file was corrupt

My function doesn't work unless i first set the media path to the directory. Is this okay?

No. It must work reguardless of the media path. You should not use getMediaPath in your function. Kelly Lyons

for file in os.listdir(directory):
if file.endswith(".jpg"):
pict= makePicture(file)
I used this as the first bit of code to set the thumbnails to half height, but when i run it i get an error saying that "There is no file at C:\Documents and Settings\Andy\My Documents\Andy\school\Compsci\JES\beach-smaller.jpg
An error occurred attempting to pass an argument to a function." whats going on?

ignore the above post i figured it out

I'm having trouble linking my thumbnails to their original size pictures... I know how to make pictures as links, but I just don't know what to put after a href="???
You should put the same thing there as you put on the thumbnail except without the height tag. Kelly Lyons


Everytime I try to run my program, it shuts down JES...any ideas why it might do that?
This is generally because your program is using too much memory. Check places where you make sounds or make pictures. Have you accidentally put that in a loop that runs many times? Or are you perhaps making a picture or a sound that is really really big? Kelly Lyons

i can't find the slides that deal with importing OS or using the open method, which is how you start from the looks of things from question 1. where might this info be?
The most helpful lecture slides are the threee that appear in week 7 on the syllabus. I do however recommend the book becuase it's got a few examples (Chapter 10 I think) that are very similar to what you are writing. Kelly Lyons

I was going by the "improved home page creator" from the book, and when I try to use the file.write(body(blahblah)), I always get an error message of some sort saying that either: "You are trying to access a part of the object that doesn't exist" or
"A local name was used before it was created. You need to define the method or variable before you try to use it." But I've checked a rechecked so many times and everything is defined before I input it. I can't even figure out how to write it out the long-handed way.
Have you written the body function? Kelly Lyons

Okay, this one is really frustrating - I was entirely finished, confirmed that it worked several times, turned it in, and then under 2 minutes later my little sister wanted to see me run it AND THEN IT WOULDN'T WORK!! - the same file "makeLinksPage.py" now will not load, it keeps saying:
"There is something wrong with the text of the file you had me try to load.
You may have not have as many closing parenthesis as opening parenthesis, or you may have tried to use a jython keyword (if, def, etc...) as a function. This cannot be done."
I haven' changed anything, and I've gone back and can't find anything wrong with it, and I don't even know what this error means about not using JES keywords when I'm writing in JES - would it be possible for one of you TAs to look at my turn-in and tell me if what you got will load or is that cheating? I'm not asking for you to tell me if it's right, but I want to know if I need to freak out over this more and turn it in again to be graded on something or move on to other stuff (pretty please)
gtg086b - turned in around midnight Saturday night
(thanks for anything you are allowed to tell me)

when we turn something in, and we choose the option to keep the copy of the file it turns in, where does that file go (where on my computer is it saved)?
Try looking in the folder that JES is in. Otherwise do a search of your computer for it. Kelly Lyons

I am struggling with this homework! One of my issues is with setting the height of my thumbnail. I wrote ...file+'" height=getHeight(picture)0.5/>... (and I even tried height=getHeight(picture)/2), but when my page appears the thumbnail dimensions appear as 1x1 pixels (a tiny square). It links to the original picture well, but this formula just doesn't change my thumbnails to half the size of the original. What's going wrong here?
If the thumbnails are really small like that, it generally isn't becuase of your height tag. When you open your html page, go to View Source and read the part where the picture tag is being created. Is there a spae between the filename and height=? That could be causing the problem. Or having the incorrect path might as well. If you view the source you can compare what you are writing to the file with what should be there, and then go into your code and fix whatever is being written wrong. Kelly Lyons


I was going by the "improved home page creator" from the book, and when I try to use the file.write(body(blahblah)), I always get an error message of some sort saying that either: "You are trying to access a part of the object that doesn't exist" or
"A local name was used before it was created. You need to define the method or variable before you try to use it." But I've checked a rechecked so many times and everything is defined before I input it. I can't even figure out how to write it out the long-handed way.
Have you written the body function? Kelly Lyons
Error: this should not happenYes, I've written the function, I followed the book exactly.
Then I would have to see the code to tell you what was wrong. You should check to make sure nothing is spelled wrong as well. Kelly Lyons

I hope someone can help me, because I am so desperate right now! Does anyone know what's wrong with these two separate pieces of code? The first is:
pic=makePicture(file)
height1=str(getHeight(pic)/2)
index=index+"""<p><a href=""+file+"">""<image src=""+file+""height="+height1+""</a></p>"""

For the pics, I only get red X's, which I have seen posted on the HW comments already, but I can't fix it. And, the pic links to my folder but not the specific file.

Add a space between the file and the word height. That may help. Kelly Lyons

The 2nd piece of code is:
writeSoundTo(blank, directory+"//"+"short_"+file)
index=index+"<p>Sound:"+"<a href="+"short_"+file+">"+"short_"+"</a>""</p>"
index=index+"<p>Sound: "+"<a href="+"full_"+file+">"+"full_"+"</a>""</p>"

I just want to know if I'm saving the new 1st and last second sound and linking to the sound correctly. I keep getting errors saying, "An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer." This error refers to the first index=index+... code. Someone please help me! I'm about to go insane!!! Thanks! ;)

For the above, you should check your parenthesis. I think that there are some extra ones near the end of the line. Or you have forgotten a plus sign Kelly Lyons

Sorry....that totally botched the page. At least you can see the little red X though. I don't know how else to post it on here so that you can see the code, but if someone just so happens to know how to help me, that'd be great! Thanks again! ;)
Review the FAQ before trying to post code here again please. It will tell you exactly how to post so that it shows up porperly Kelly Lyons

I am having trouble making the pictures into links. Is this correct?
a href="'+directory+'"picture.html"> image src="+file+"\> /a>
(For the code above, I had to remove half of the brackets that look like a less than sign for it to show up, so just ignore that.)
Also, when we make the links to the sounds, should the target be directory\sound.html, or directory\sound.wav?
The sound should be a .wav file. And you need a slash between the directory and the name of the picture after the a href. Kelly Lyons


I'm working on my code and I keep getting following errors:  
website.write('<a href= " ' +file+ ' ">' + '<img src = " ' +file+ ' "    
syntax error

writeSoundTo(emptysound, dir + "//" + "short_" + file)  
spacing error

Thanks so much for any help!  



The first line has no closing parenthesis. And a spacing error may refer to it not being indented correctly or it could be a syntax error on a pervious line. Kelly Lyons



when i use this for loop...
for pics in os.listdir(dir):
if pics.endswith(".jpg"):
pic=makePicture(dir + "//" + pics)
height = int(getHeight(pic)/2)
print height
print pics
file.write('<p>filename- ' + pics + '\n')"
file.write('<a href="' + pics + '"><image src="' + pics + '" height="' + height + '" /></a></p>\n')"


(my tabbing is correct, i just can't get it to show up on here)

i receive an error in regards to the last line saying...

An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.

this does not make sense to me because both pics and height print out with the correct values, so why does it think that height (the input causing the problem) is a function and not just a value to be placed there like pics is?

john churchman
gtg261r

You convert the height to an Int instead of a String. Just swap out int() or str() in that 4th line. Greg Leo


a href="'+directory+'"picture.html"> image src="+file+"\> /a>
If I need to add a slash between the directory and the name of the picture, how should I do this? I keep getting syntax errors.


You can always just add an extra slash when you input the directory into the program. That should take care of the problem. Greg Leo


directory + '//' + picture Kelly Lyons

I understand everything but the simplest thing. How do you get the html page to show in the wanted directory?


when you do file.open you need to open directory + index.html. Otherwise it will open the index.html file in the default directory that JES is in. Kelly Lyons

I'm getting really confused with the sounds...and I'm sure I'm making it much more complicated than it's supposed to be. I've got all my pictures in order and I've got the program identifying sounds longer than two seconds. How do we make the sample sounds then? Are we allowed to fill in the first two seconds with the first and last second of the clip and then just put silence over the rest of it, or is there something I'm missing? Also, how do I define how far to go into the clip.....a second from the beginning and a second from the ending? I tried to tell it get/set the sampleValue from, say, range(getSamplingRate,(2 getSamplingRate)) since that should theoretically be one second away, right? It was having none of that though. Blah....I'm probably just missing something obvious here and my brain is dull after taking a huge test this morning...so if you guys have any ideas please let me know. Is there a certain lecture that deals with the kind of coding needed to make these sound sample clips? Thanks!


You should use the makeEmptySound function to create a 2 second long sound. The first second in this sound should be the first second of the sound you are looking at. The last second of the 2 second long sound should come from the last second of the sound.
range(getSamplingRate(sound),getsamplingRate(sound)*2 
will give you the samples in the 2nd second of the sound, not the first. Shouldn't your range start at 1? As for getting from the end of the sound, you can get the length, and you can get the number of samples in one second. The length minus the number of samples in one second will give you the sample beginning the last second in the sound. Hope that helps Kelly Lyons|

What is wrong with this code? It keeps giving me syntax errors.
a href=\""directory+'//'+file+"\"> image src=\""+file+"\"\> /a>
(I had to remove all of the less than symbols for it to show up.)

It's hard to see what the line actually is if you are removing things to make it show up. Read the faq about how to make things show up on the coweb. But from looking at it, it seems as if the quotations are not correctly balanced. You are also missing a plus sign before the directory. Kelly Lyons


I used this as my code for short sound, but the sound plays the full time.

def ShortSound(sound):
  short=makeEmptySound(2)
  for sample in range (1, int(getSamplingRate(sound))):
    value=getSampleValueAt(sound, sample)
    setSampleValueAt(short, sample, value)
  for sample in range (1, int(2*getSamplingRate(sound))):
    source=getSampleValueAt(sound, sample)
    setSampleValueAt(short, sample, source)
  return short


This is becuase you are simply copying the first two seconds of the sound into the sample instead of the first and last second. Kelly Lyons


for file in os.listdir(directory):
if file.endswith(".jpg"):
pict= makePicture(file)
I used this as the first bit of code to set the thumbnails to half height, but when i run it i get an error saying that "There is no file at C:\JES\HW4
An error occurred attempting to pass an argument to a function." whats going on?
You only makePicture of file, so it assumes the directory is the default JES directory. You need to makePicture of the directory + '//' + file Kelly Lyons



What is the password to attach the files onto coweb?



Links to this Page