Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. How to integrate wget with PyQT?

How to integrate wget with PyQT?

Scheduled Pinned Locked Moved 3rd Party Software
8 Posts 3 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dinesh Raja
    wrote on last edited by
    #1

    Hi currently i am developing an small pyqt tool and its a front end for Wget since i am developing it on Linux i could invoke the wget by subprocess.call but i need to deploy this application in windows too how can i accomplish this ?

    kindly guide me to complete this application.

    @import sys
    from PyQt4 import QtGui, QtCore
    import subprocess
    class Home(QtGui.QWidget):
    def init(self):
    QtGui.QMainWindow.init(self)
    self.setWindowTitle('Dinesh Downloader')
    self.vbox = QtGui.QVBoxLayout()
    self.setLayout(self.vbox)
    self.FileNameLabel = QtGui.QLabel('No file selected')
    self.vbox.addWidget(self.FileNameLabel)
    FileChooserButton = QtGui.QPushButton('Choose file', self)
    self.vbox.addWidget(FileChooserButton)
    self.connect(FileChooserButton, QtCore.SIGNAL('clicked()'), self.get_fname)
    Output=QtGui.QTextEdit()
    self.vbox.addWidget(Output)
    def get_fname(self):
    fname = QtGui.QFileDialog.getOpenFileName(self, 'Select file')
    subprocess.call(["wget", "-i", fname])
    if fname:
    self.FileNameLabel.setText(fname)
    else:
    self.FileNameLabel.setText('No file selected')

    if name == "main":
    app = QtGui.QApplication(sys.argv)
    gui = Home()
    gui.show()
    app.exec_()@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      From the top of my mind, did you try with python's wget library ?

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dinesh Raja
        wrote on last edited by
        #3

        [quote author="SGaist" date="1404204795"]Hi and welcome to devnet,

        From the top of my mind, did you try with python's wget library ?

        Hope it helps[/quote]

        Nope i dint but just now took a look at that all i want to do is to perform
        wget -i Downloads.txt where the text file will have all the download links

        I think Python's wget library not providing this feature

        1 Reply Last reply
        0
        • jazzycamelJ Offline
          jazzycamelJ Offline
          jazzycamel
          wrote on last edited by
          #4

          SGaist is completely correct, use the Python wget module (easy_install wget). All the "-i" option does is tell wget to open the file and download each of the links it contains, we can easily do the same in python. The following is a complete working example:

          pyqtwget.py
          @
          import sip
          sip.setapi('QString',2)
          sip.setapi('QVariant',2)

          from PyQt4.QtCore import *
          from PyQt4.QtGui import *
          import wget

          class Widget(QWidget):
          def init(self, parent=None, **kwargs):
          QWidget.init(self, parent, **kwargs)

              self.setWindowTitle("wget")
          
              l=QVBoxLayout(self)
          
              self._fileNameLabel=QLabel("No file selected", self)
              l.addWidget(self._fileNameLabel)
          
              self._chooseFile=QPushButton("Choose File...", self, clicked=self.getFileName)
              l.addWidget(self._chooseFile)
          
              self._progress=QProgressBar(self)
              l.addWidget(self._progress)
          
              self._progressLabel=QLabel(self)
              l.addWidget(self._progressLabel)
          
          @pyqtSlot()
          def getFileName(self):
              fileName=QFileDialog.getOpenFileName(self, "Select File")
              if not fileName: return
              self._fileNameLabel.setText(fileName)
          
              def updateProgress(current, total, width=80):
                  self._progress.setMaximum(total)
                  self._progress.setValue(current)
                  QApplication.processEvents()
                  return ""
          
              with open(fileName, 'rb') as f:
                  for line in f:
                      self._progressLabel.setText("Downloading '{0}'".format(line.strip()))
                      wget.download(line.strip(), bar=updateProgress)
          

          if name=="main":
          from sys import argv, exit

          a=QApplication(argv)
          w=Widget()
          w.show()
          w.raise_()
          exit(a.exec_())
          

          @

          downloads.txt
          @
          http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3
          http://www.futurecrew.com/skaven/song_files/mp3/corruptor.mp3
          http://www.futurecrew.com/skaven/song_files/mp3/hold_me.mp3
          @

          Hope this helps ;o)

          For the avoidance of doubt:

          1. All my code samples (C++ or Python) are tested before posting
          2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dinesh Raja
            wrote on last edited by
            #5

            [quote author="jazzycamel" date="1404213661"]SGaist is completely correct, use the Python wget module (easy_install wget). All the "-i" option does is tell wget to open the file and download each of the links it contains, we can easily do the same in python. The following is a complete working example:

            pyqtwget.py
            @
            import sip
            sip.setapi('QString',2)
            sip.setapi('QVariant',2)

            from PyQt4.QtCore import *
            from PyQt4.QtGui import *
            import wget

            class Widget(QWidget):
            def init(self, parent=None, **kwargs):
            QWidget.init(self, parent, **kwargs)

                self.setWindowTitle("wget")
            
                l=QVBoxLayout(self)
            
                self._fileNameLabel=QLabel("No file selected", self)
                l.addWidget(self._fileNameLabel)
            
                self._chooseFile=QPushButton("Choose File...", self, clicked=self.getFileName)
                l.addWidget(self._chooseFile)
            
                self._progress=QProgressBar(self)
                l.addWidget(self._progress)
            
                self._progressLabel=QLabel(self)
                l.addWidget(self._progressLabel)
            
            @pyqtSlot()
            def getFileName(self):
                fileName=QFileDialog.getOpenFileName(self, "Select File")
                if not fileName: return
                self._fileNameLabel.setText(fileName)
            
                def updateProgress(current, total, width=80):
                    self._progress.setMaximum(total)
                    self._progress.setValue(current)
                    QApplication.processEvents()
                    return ""
            
                with open(fileName, 'rb') as f:
                    for line in f:
                        self._progressLabel.setText("Downloading '{0}'".format(line.strip()))
                        wget.download(line.strip(), bar=updateProgress)
            

            if name=="main":
            from sys import argv, exit

            a=QApplication(argv)
            w=Widget()
            w.show()
            w.raise_()
            exit(a.exec_())
            

            @

            downloads.txt
            @
            http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3
            http://www.futurecrew.com/skaven/song_files/mp3/corruptor.mp3
            http://www.futurecrew.com/skaven/song_files/mp3/hold_me.mp3
            @

            Hope this helps ;o)[/quote]

            Thanks for the code friend,i got the GUI up running but i got some error while downloading here it is

            @"Qt Warning - invalid keysym: dead_actute"
            Traceback (most recent call last):
            File "pywget.py", line 44, in getFileName
            wget.download(line.strip(), bar=updateProgress)
            File "/usr/lib/python3.4/site-packages/wget.py", line 293, in download
            filename = filename_from_url(url) or "."
            File "/usr/lib/python3.4/site-packages/wget.py", line 40, in filename_from_url
            if len(fname.strip(" \n\t.")) == 0:
            TypeError: Type str doesn't support the buffer API
            @
            But now i have got some idea i will try to use them will post it here if get struct

            1 Reply Last reply
            0
            • jazzycamelJ Offline
              jazzycamelJ Offline
              jazzycamel
              wrote on last edited by
              #6

              Its simple enough, I wrote my example using Python 2.7 which uses strings by default, you're using 3.4 which expects unicode. It seems the wget module is another victim of the 2to3 conversion process. If you change line 44 as follows it will work fine:

              @
              wget.download(str(line.strip(), encoding="utf8"), bar=updateProgess)
              @

              Hope this helps ;o)

              For the avoidance of doubt:

              1. All my code samples (C++ or Python) are tested before posting
              2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dinesh Raja
                wrote on last edited by
                #7

                [quote author="jazzycamel" date="1404225693"]Its simple enough, I wrote my example using Python 2.7 which uses strings by default, you're using 3.4 which expects unicode. It seems the wget module is another victim of the 2to3 conversion process. If you change line 44 as follows it will work fine:

                @
                wget.download(str(line.strip(), encoding="utf8"), bar=updateProgess)
                @

                Hope this helps ;o)[/quote]

                Again thanks for the correction buddy another small problem was the program is downloading the first URL not the rest should i readlines()??

                1 Reply Last reply
                0
                • jazzycamelJ Offline
                  jazzycamelJ Offline
                  jazzycamel
                  wrote on last edited by
                  #8

                  No, it should work fine assuming the lines in your file are terminated correctly. The code at lines 41 and 42 as follows:

                  @
                  with open(fileName, 'rb') as f:
                  for line in f:
                  @

                  Takes care of opening the file and the iterating over it line by line. This works fine for me with Windows and Mac and Python versions 2.7 and 3.4. You can use readlines() if you like but it shouldn't be necessary.

                  For the avoidance of doubt:

                  1. All my code samples (C++ or Python) are tested before posting
                  2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved