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


This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

hw6

def makeNewsTickerTape(dir):
news1, news2, news3 = getNews()
makeTickerTape(news1, news2, news3, dir)

def makeTickerTape(str1, str2, str3, dir):
for frame in range(100,200):
canvas: makePicture(getMediaPath("640x480.jpg")
addText(canvas, 600-((frame-99)3), 100, str1)
addText(canvas, 600-((frame-99)3), 200, str2)
addText(canvas, 600-((frame-99)3), 300, str3)

import urllib

def getNews():

newsWebpage = "http://news.com.com"
#Location for output text file (change)
outputFileLocation = r"C:\\Documents and Settings\Owner\Desktop\JES\\TopNewsStories.txt"

#The actual grabbing of the webpage and storing its information in info
info = grabWebpage(newsWeb)
#The finding of information on the Yahoo webpage
breakdownTopStories(info, outputFileLocation)


def grabWebpage(webpageLocation):
webpageConnection = urllib.urlopen(webpageLocation)
webpageInfo = webpageConnection.read()
webpageConnection.close()
return webpageInfo

def breakdownTopStories(htmlInfo, outputFileLocation):

#Opens the output file and prepares it from w-riting t-ext
outputFile = open(outputFileLocation, "wt")

#What we will want to find to get everyting started.
startPhrase = '
  • Senate passes scaled-back copyright measure  #What we will want to find the location of in order to stop the while loop.
    stopPhrase = '
  • Store trots out Treo Monday, November 22, 2004


  • #Finding our starting and stopping point.
    #Starting point is stored in index becuase we will be updating
    index = htmlInfo.find(startPhrase)
    stoppingPoint = htmlInfo.find(stopPhrase,index)

    #While we havent reached or passed by our stopping point, do all that is below.
    while(index = stoppingPoint):

    # Find a Row of Data
    dataRow = htmlInfo.find("",index)

    #Find Date
    start = htmlInfo.find('align="right',dataRow)
    dateStart = htmlInfo.find(">",start)+1
    dateEnd = htmlInfo.find("",dateStart)
    #Write the date and add a tab to the end
    outputFile.write(htmlInfo[dateStart:dateEnd]+"\t")

    #Find Open
    start = htmlInfo.find('align="right',dateEnd)
    openStart = htmlInfo.find(">",start)+1
    openEnd = htmlInfo.find("",openStart)
    #Write the opening price and add a tab to the end
    outputFile.write(htmlInfo[openStart:openEnd]+"\t")

    #Find High
    start = htmlInfo.find('align="right',openEnd)
    highStart = htmlInfo.find(">",start)+1
    highEnd = htmlInfo.find("",highStart)
    #Write the daily high and add a tab to the end
    outputFile.write(htmlInfo[highStart:highEnd]+"\t")

    #Find Low
    start = htmlInfo.find('align="right',highEnd)
    lowStart = htmlInfo.find(">",start)+1
    lowEnd = htmlInfo.find("",lowStart)
    #Write the daily low and add a tab to the end
    outputFile.write(htmlInfo[lowStart:lowEnd]+"\t")

    #Find Close
    start = htmlInfo.find('align="right',lowEnd)
    closeStart = htmlInfo.find(">",start)+1
    closeEnd = htmlInfo.find("",closeStart)
    #Write the dailt close and add a tab to the end
    outputFile.write(htmlInfo[closeStart:closeEnd]+"\t")

    #Find REMOVEDlume
    start = htmlInfo.find('align="right',closeEnd)
    volumeStart = htmlInfo.find(">",start)+1
    volumeEnd = htmlInfo.find("",volumeStart)
    #Write the volume traded and add a tab to the end
    outputFile.write(htmlInfo[volumeStart:volumeEnd]+"\t")

    #Find Adj Close
    start = htmlInfo.find('align="right',volumeEnd)
    adjCloseStart = htmlInfo.find(">",start)+1
    adjCloseEnd = htmlInfo.find("",adjCloseStart)
    #Write the adjREMOVEDted closing price and add a newline to the end
    outputFile.write(htmlInfo[adjCloseStart:adjCloseEnd]+"\n")

    #Update
    index = adjCloseEnd + 1

    #Close the output File
    outputFile.close()

    Link to this Page