Profilo di o88onero

Nome o88onero
Indirizzo email n/a
Messaggi5
  • Re: ERRORE: "NameError: name 'self' is not defined"
    Forum >> Programmazione Python >> Scripting
    @cm

    Sono riuscito a mettere a posto lo script però c'è ancora qualcosa che non va, quando cerco di fare il download mi si presentano questi messaggi:

    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'
    
    

    Non riesco a capire se effettivamente avviene il download dei file, non ne trovo, oppure sia un problema di conversione in pdf.
  • Re: ERRORE: "NameError: name 'self' is not defined"
    Forum >> Programmazione Python >> Scripting
    @ cm

    Ho corretto in alcuni punti l'identazione, ora lo script è uguale a quello che hai postato tu ma quando lancio il comando mi da sempre lo stesso errore:

    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        from mebook import downloader
      File "mebook.py", line 88, in <module>
        print("Well done! "+self.isbn+".pdf created!")
    NameError: name 'self' is not defined
  • Re: ERRORE: "NameError: name 'self' is not defined"
    Forum >> Programmazione Python >> Scripting
    @ Daniele aka Palmux, grazie per l'aiuto.

    Voglio ottenere lo stesso risultato che viene mostrato in questo articolo dove c'è anche un video dimostrativo:

    http://ukesec.altervista.org/estrarre-i-pdf-da-mebook-attraverso-iflipit/

    dato che non mi sono mai cimentato con linux, nè tantomeno con python, non riesco a capire il procedimento da seguire per raggiungere lo scopo e l'autore dell'articolo non risulta contattabile.
  • Re: ERRORE: "NameError: name 'self' is not defined"
    Forum >> Programmazione Python >> Scripting
    Fatto. :fingers-crossed:
  • ERRORE: "NameError: name 'self' is not defined"
    Forum >> Programmazione Python >> Scripting
    Premetto che sono un neofita di python.

    In rete ho trovato questo script:

    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
                    s=arrnewpos
                    arr=s
                    arrnewpos = 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!") 

    Nelle istruzioni per l'utilizzo, l'autore dice di creare un file *.py con il suddetto script poi aprire la linea di comando di python e digitare "from *.py import downloader".

    Dopo aver digitato il comando mi appare il seguente errore:
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        from mebook import downloader
      File "mebook.py", line 88, in <module>
        print("Well done! "+self.isbn+".pdf created!")
    NameError: name 'self' is not defined

    Chi mi aiuta indicandomi l'esatta procedura da seguire per far funzionare il codice?







    --- Ultima modifica di o88onero in data 2016-09-20 08:29:57 ---

    --- Ultima modifica di o88onero in data 2016-09-20 08:31:45 ---