jacensolo
August 30th, 2008, 11:10 PM
I'm pretty sure this was working the other day. I opened it up to work on it again in Geany and it didn't work. So I switched back to Idle and I'm getting an IOError.
I'm trying to get this to open woot.com and retrieve the information I want and save it to a different file each day. It's not nearly complete though.
I created a basic library (to learn OO mainly) since I plan to do this with other sites too.
Error
Traceback (most recent call last):
File "/home/killian/Python/woot.py", line 24, in <module>
f = open("info", 'r')
IOError: [Errno 2] No such file or directory: 'info'
Library:
import urllib
class Site:
def __init__(self, site):
try:
self.site = urllib.urlopen(site)
except IOError:
print "Error: Could not find site"
def writetofile(self, filepath):
try:
self.filepath = str(filepath)
self.file = open(self.filepath, 'w')
except TypeError:
print "Please enter a string, not numbers!"
except IOError:
print "Please enter a valid path."
print "If you are sure this is correct then there is an unknown error"
try:
if self.file and self.site:
for line in self.site:
self.file.write(line)
except:
print "could not write to file"
Program:
import weblib
def openwoot():
yield weblib.Site('http://www.woot.com')
def savewoot(obj):
name = raw_input("Please enter the name of the file\n")
path = raw_input("Please enter the path in which you would like to save the file\n")
string = path + name
print string
obj.writetofile(string)
try:
f = open("info", 'r')
except IOError:
woot = openwoot()
f.close()
print "This is your firt time running the program"
folder = raw_input("Please enter a folder to save your pages and pictures\n")
f = open("info", 'w')
f.write(folder)
f.close()
f = open("info", 'r')
finally:
directory = f.readline()
I EVEN MADE AN IO EXCEPTION BUT IT DIDN'T COME UP! I know this exception worked before.
I'm trying to get this to open woot.com and retrieve the information I want and save it to a different file each day. It's not nearly complete though.
I created a basic library (to learn OO mainly) since I plan to do this with other sites too.
Error
Traceback (most recent call last):
File "/home/killian/Python/woot.py", line 24, in <module>
f = open("info", 'r')
IOError: [Errno 2] No such file or directory: 'info'
Library:
import urllib
class Site:
def __init__(self, site):
try:
self.site = urllib.urlopen(site)
except IOError:
print "Error: Could not find site"
def writetofile(self, filepath):
try:
self.filepath = str(filepath)
self.file = open(self.filepath, 'w')
except TypeError:
print "Please enter a string, not numbers!"
except IOError:
print "Please enter a valid path."
print "If you are sure this is correct then there is an unknown error"
try:
if self.file and self.site:
for line in self.site:
self.file.write(line)
except:
print "could not write to file"
Program:
import weblib
def openwoot():
yield weblib.Site('http://www.woot.com')
def savewoot(obj):
name = raw_input("Please enter the name of the file\n")
path = raw_input("Please enter the path in which you would like to save the file\n")
string = path + name
print string
obj.writetofile(string)
try:
f = open("info", 'r')
except IOError:
woot = openwoot()
f.close()
print "This is your firt time running the program"
folder = raw_input("Please enter a folder to save your pages and pictures\n")
f = open("info", 'w')
f.write(folder)
f.close()
f = open("info", 'r')
finally:
directory = f.readline()
I EVEN MADE AN IO EXCEPTION BUT IT DIDN'T COME UP! I know this exception worked before.