HELP ME! ... IOError: [Errno 2] No such file or directory:

This is the place for queries that don't fit in any of the other categories.

HELP ME! ... IOError: [Errno 2] No such file or directory:

Postby The_Droog » Fri Sep 23, 2016 6:46 am

I can not be run this script:

Code: Select all
import requests,re,sys, os, threading, time
import img2pdf  # https://github.com/josch/img2pdf
import PyPDF2  # https://github.com/mstamy2/PyPDF2

class downloader:
   def __init__(self):
      self.session = requests.Session()
      self.email = ""
      self.password = ""
      self.isbn = ""

   def login(self,email, password):
      print "Loggin in..."
      html=self.session.get("https://www.mondadorieducation.it/app/mondadorieducation/login/loginJsonp?username="+email+"&password="+password+"&format=json&jsoncallback=jsonp11").text
      if not '"result":"OK"' in html: sys.exit("Login failed, check your email/password!")
      print "Login successful."
      self.session.get("http://libropiuweb.mondadorieducation.it/mod_connect/login?urlRitorno=http%3A%2F%2Flibropiuweb.mondadorieducation.it%2F")
      return re.search('"username":"(.*?)"',html).group(1)

   def decrypt(self,data,page):
      data=data.replace('viewer._imgl('+str(page)+',"','').replace('");\nviewer._imgl('+str(page)+');','')
      data=data.decode('string_escape')
      m="fb69218f41737d7da84b1e39a949dbc2"
      arr=list(data)
      for j in range(3):
         for i in range(95,-1,-1):
            newpos=ord(m[i % 32]) % 96
            f=arr[i]
            s=arr[newpos]
            arr[i]=s
            arr[newpos] = f
      data=''.join(arr)
      return data

   def get_npages(self,username,isbn):
      print "Getting page count..."
      html=self.session.get("http://iflipit.mondadorieducation.it/desktop/index.php?accesslevel=st-pl&usr="+username+"&iss="+isbn+"&fil=iss").text
      return int(re.search('"pagesCount":(.*?),',html).group(1))

   def download(self,username,isbn,pagen):
      sys.stdout.write("\rDownloading page n. "+str(pagen)+"...")
      sys.stdout.flush()
      pageid="0"*(3-len(str(pagen)))+str(pagen)
      f=open("/tmp/"+isbn+"_"+str(pagen)+".jpg","wb")
      try:
         content=self.session.get("http://iflipit.mondadorieducation.it/desktop/index.php?usr="+username+"&iss="+isbn+"&fld=sdf&id="+pageid+"&ext=js").content
      except:
         self.download(username,isbn,pagen)
      data=self.decrypt(content,pagen)
      f.write(data)
      f.close()

   def start(self):
      username=self.login(self.email,self.password)
      npages=self.get_npages(username,self.isbn)

      print "Starting downloading "+str(npages)+" pages."
      pagen=1
      signal=1
      while signal:
         for i in range(30-threading.activeCount()):
            if pagen==npages+1:signal=0;break;
            threading.Thread(target=self.download,args=(username,self.isbn,pagen,)).start()
            pagen+=1
         time.sleep(1)

      while 1:
         if threading.activeCount()==1:
            print "\nDone, got all pages."
            break
         else:
            time.sleep(1)

      print("\nConverting images to PDF format...")
      for npage in range(1,npages+1):
         pdf_bytes=img2pdf.convert(["/tmp/"+self.isbn+"_"+str(npage)+".jpg"])
         f = open("/tmp/"+self.isbn+"_"+str(npage)+".pdf","wb")
         f.write(pdf_bytes)
         f.close()
         sys.stdout.write("\rConverting page n. "+str(npage)+"...")
         sys.stdout.flush()
   
      merger = PyPDF2.PdfFileMerger()
      print("\nMerging everything...")
      for npage in range(1,npages+1):
         merger.append(PyPDF2.PdfFileReader(open("/tmp/"+self.isbn+"_"+str(npage)+'.pdf','rb')))
      merger.write(self.isbn+".pdf")
      print("Well done! "+self.isbn+".pdf created!")   


This is the error that I get when I run the command:

Code: Select all
Loggin in...
Login successful.
Getting page count...
Starting downloading 450 pages.

Downloading page n. 1...
Downloading page n. 2...
Downloading page n. 3...
Downloading page n. 4...
Downloading page n. 5...
Downloading page n. 6...
Downloading page n. 7...
Downloading page n. 8...
Downloading page n. 9...
Downloading page n. 10...
Downloading page n. 11...
Downloading page n. 12...
Downloading page n. 13...
Downloading page n. 14...
Downloading page n. 15...
Downloading page n. 16...
Downloading page n. 17...
Downloading page n. 18...
Downloading page n. 19...
Downloading page n. 20...
Downloading page n. 21...
Downloading page n. 22...
Downloading page n. 23...
Downloading page n. 24...
Downloading page n. 25...
Downloading page n. 26...
Downloading page n. 27...
Downloading page n. 28...Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "mebook.py", line 44, in download
    f=open("/tmp/"+isbn+"_"+str(pagen)+".jpg","wb")
IOError: [Errno 2] No such file or directory: '/tmp/978882473968_1.jpg'
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "mebook.py", line 44, in download
    f=open("/tmp/"+isbn+"_"+str(pagen)+".jpg","wb")
IOError: [Errno 2] No such file or directory: '/tmp/978882473968_2.jpg'
Exception in thread Thread-3:

...

Downloading page n. 449...
Downloading page n. 450...Exception in thread Thread-449:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "mebook.py", line 44, in download
    f=open("/tmp/"+isbn+"_"+str(pagen)+".jpg","wb")
IOError: [Errno 2] No such file or directory: '/tmp/978882473968_449.jpg'
Exception in thread Thread-450:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "mebook.py", line 44, in download
    f=open("/tmp/"+isbn+"_"+str(pagen)+".jpg","wb")
IOError: [Errno 2] No such file or directory: '/tmp/978882473968_450.jpg'



Who will help me to get this script?
Last edited by micseydel on Fri Sep 23, 2016 3:18 pm, edited 1 time in total.
Reason: Initial post lock.
The_Droog
 
Posts: 1
Joined: Fri Sep 23, 2016 6:21 am

Re: HELP ME! ... IOError: [Errno 2] No such file or director

Postby micseydel » Fri Sep 23, 2016 3:20 pm

Where did this come from? Why are you responsible for it? What have you tried to fix it? Do you know some Python, are you interested in learning, or do you need it to be done for you?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: HELP ME! ... IOError: [Errno 2] No such file or director

Postby metulburr » Fri Sep 23, 2016 9:18 pm

Describe the symptoms of your problem carefully and clearly.
Describe the environment in which it occurs. Provide the Python version, execution process, Operating System, 3rd party library, program structure, etc.
Describe the research you did to try and understand the problem before you asked the question.
Describe the diagnostic steps you took to try and pin down the problem yourself before you asked the question.
Describe any possibly relevant recent changes in your computer or software configuration. How did you install X program? From where? Provide the install link. Describe how you installed it, etc.
If at all possible, provide a way to reproduce the problem in a controlled environment.
Describe the goal, not the step. If you are trying to find out how to do something, begin by describing the goal. Only then describe the particular step towards it that you are blocked on.
Describe your problem's symptoms in chronological order
Describe the problem's symptoms, not your guesses
Write in clear, grammatical, correctly-spelled language
Use meaningful, specific subject headers
http://python-forum.io/misc.php?action=help&hid=19
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests