I am quite new to python…
import sys, os, time, py4chan, urllib from urllib2 import urlopen, URLError, HTTPError
def refreshthread(boardin,no):
global thread
global topic
board = py4chan.Board(boardin)
thread = board.getThread(int(no))
topic = thread.topic
time.sleep(2.5)
def dlfile(url, folder):
try:
f = urlopen(url)
with open(folder + "/" + os.path.basename(url), "wb") as local_file:
local_file.write(f.read())
print "Downloaded to " + str(folder + "/" + os.path.basename(url))
except HTTPError, e:
print "HTTP Error:", e.code, url
except URLError, e:
print "URL Error:", e.reason, url
def getsize(uri):
file = urllib.urlopen(uri)
size = file.headers.get("content-length")
file.close()
return str(int(size) / 1024)
def main():
boardtag = str(raw_input("Board: "))
threadno = int(raw_input("Thread id: "))
folder = str(raw_input("Save to folder: "))
print "Getting thread information..."
refreshthread(boardtag,threadno)
print "Subject: " + topic.Subject
while(True):
if not os.path.exists(folder): os.makedirs(folder)
refreshthread(boardtag,threadno)
for imgurl in thread.Files():
if imgurl is not None and not os.path.exists(folder + "/" + os.path.basename(imgurl)):
print "A wild image appears! " + "(" + getsize(imgurl) + "kb)"
dlfile(imgurl,folder)
else:
pass
if __name__ == '__main__':
main()
I coded this on linux and it runs perfectly, but if I run this on windows, I get this error:
TypeError: __init__() takes exactly 4 arguments (2 given)
Which is quite strange as I haven’t defined init.
Could this be an init from another module?
The py4chan module seems to work fine if i code other scripts.
Both machines have same python version too.
EDIT(Full error):
Getting thread information...
Traceback (most recent call last):
File "4chan.py", line 59, in <module>
main()
File "4chan.py", line 46, in main
refreshthread(boardtag,threadno)
File "4chan.py", line 15, in refreshthread
board = py4chan.Board(boardin)
TypeError: __init__() takes exactly 4 arguments (2 given)
*Edit:*Okay, i had two different modules of the same name. All working now.
I shouldn’t be allowed on this website.
The
py4chan.Boardclass needs to be constructed with 3 arguments, not 1. This line in therefreshthreadfunction:Should look something this: