Exemple #1
0
 def _parseMultipleShortFiles(self):
     '''Deprecated: it is done on the selection step'''
     failed = 0
     succeed = 0
     if len(self._filenames) < 1:
         logger.info("Please, select files before parsing")
         return
     for filename in self._filenames:
         logger.info("Parsing file " + filename.split('/')[-1] +
                     " from TeX")
         try:
             self._writeups.append(ShortWriteUp.parseFromTex(filename))
             succeed += 1
             logger.info(self._writeups[-1])
             logger.info("Parsing done...")
         except Exception as ex:
             failed += 1
             logger.debug(str(ex))
             logger.info(
                 "Error in parsing the document. Please, select a file with the correct latex structure"
             )
             #TODO the error chain for getting a message to the user
     logger.info("For " + str(len(self._filenames)) +
                 " documents:\nFailed: " + str(failed) + "\nSucceed: " +
                 str(succeed))
Exemple #2
0
 def _loadDirectoryMultipleShort(self):
     directory = QtGui.QFileDialog.getExistingDirectory()
     logger.debug(directory)
     self._filenames = [directory + "/" + f for f in listdir(directory)]
     self.ui.loadededFilesShortTextEdit.clear()
     if len(self._filenames) < 1:
         logger.info("Please, select files before parsing")
         return
     failed = 0
     succeed = 0
     for filename in self._filenames:
         logger.info("Parsing file " + filename.split('/')[-1] +
                     " from TeX")
         try:
             self._writeups.append(ShortWriteUp.parseFromTex(filename))
             self.ui.loadededFilesShortTextEdit.insertPlainText(
                 filename.split('/')[-1] + "\n")
             succeed += 1
             logger.info(self._writeups[-1])
             logger.info("Parsing done...")
         except Exception as ex:
             failed += 1
             logger.debug(str(ex))
             logger.info(
                 "Error in parsing the document. Please, select a file with the correct latex structure"
             )
             #TODO the error chain for getting a message to the user
     logger.info("For " + str(len(self._filenames)) +
                 " documents:\nFailed: " + str(failed) + "\nSucceed: " +
                 str(succeed))
 def _parseSingleShortFile(self):
     '''Deprecated: it is done on the selection step'''
     filename = self.ui.texShortTb.toPlainText()
     logger.info("Parsing file " + filename.split('/')[-1] + " from TeX")
     try:
         writeup = ShortWriteUp.parseFromTex(filename)
         self.setWriteUp(writeup)
         logger.info("Parsing done...")
     except Exception as ex:
         logger.info("Error in parsing the document. Please, select a file with the correct latex structure")
         logger.debug(str(ex))
Exemple #4
0
def getDocFromWeb():
    #Find for the short writeups
    conn = http.client.HTTPConnection("goossens.web.cern.ch")
    conn.request("GET", "/goossens/cernlibshort.html")
    soup = BeautifulSoup(conn.getresponse().read(), 'html.parser')

    #Fill the information from each of them and store it
    for cat in soup.find_all('h2'):
        if re.match("[A-Z]", cat.get_text()):
            print("Got a category:")
            print(cat.get_text())
            print("Getting documents on it:")
            if cat.next_sibling.next_sibling and cat.next_sibling.next_sibling.name == "dl":
                dl = cat.next_sibling.next_sibling
                for dt in dl.children:
                    if dt.name == "dt":
                        urlDoc = "/goossens/" + dt.a['href'][2:] # Here i got the html link
                        print("Getting link to html doc at:", urlDoc)
                        # conn = http.client.HTTPConnection("goossens.web.cern.ch")
                        doc = BeautifulSoup(auxTools.getFixedHTML('http://goossens.web.cern.ch'+urlDoc), 'html.parser')
                        print("Parsing:", doc.title.get_text())
                        proc = ShortWriteUp()
                        proc.loadFromHTML(doc)
                        ShortWriteUp.insertShortWriteup(proc)
                        print(proc)
Exemple #5
0
 def _parseSingleShortFile(self):
     '''Deprecated: it is done on the selection step'''
     filename = self.ui.texShortTb.toPlainText()
     logger.info("Parsing file " + filename.split('/')[-1] + " from TeX")
     try:
         writeup = ShortWriteUp.parseFromTex(filename)
         self.setWriteUp(writeup)
         logger.info("Parsing done...")
     except Exception as ex:
         logger.info(
             "Error in parsing the document. Please, select a file with the correct latex structure"
         )
         logger.debug(str(ex))
 def _selectSingleShortFile(self):
     #TODO: I have to filter only .tex files
     filename = QtGui.QFileDialog.getOpenFileName(filter="LaTeX (*.tex)")
     logger.info("Parsing file: " + filename)
     try:
         writeup = ShortWriteUp.parseFromTex(filename)
         self.setWriteUp(writeup)
         logger.info(writeup)
         logger.info("Parsing done...")
         self.ui.texShortTb.setText(filename)
     except Exception as ex:
         logger.info("Error in parsing the document. Please, select a file with the correct latex structure")
         logger.debug(str(ex))
Exemple #7
0
 def _selectSingleShortFile(self):
     #TODO: I have to filter only .tex files
     filename = QtGui.QFileDialog.getOpenFileName(filter="LaTeX (*.tex)")
     logger.info("Parsing file: " + filename)
     try:
         writeup = ShortWriteUp.parseFromTex(filename)
         self.setWriteUp(writeup)
         logger.info(writeup)
         logger.info("Parsing done...")
         self.ui.texShortTb.setText(filename)
     except Exception as ex:
         logger.info(
             "Error in parsing the document. Please, select a file with the correct latex structure"
         )
         logger.debug(str(ex))
 def _parseMultipleShortFiles(self):
     '''Deprecated: it is done on the selection step'''
     failed = 0
     succeed = 0
     if len(self._filenames) < 1:
         logger.info("Please, select files before parsing")
         return
     for filename in self._filenames:
         logger.info("Parsing file " + filename.split('/')[-1] + " from TeX")
         try:
             self._writeups.append(ShortWriteUp.parseFromTex(filename))
             succeed += 1
             logger.info(self._writeups[-1])
             logger.info("Parsing done...")
         except Exception as ex:
             failed += 1
             logger.debug(str(ex))
             logger.info("Error in parsing the document. Please, select a file with the correct latex structure")
             #TODO the error chain for getting a message to the user
     logger.info("For " + str(len(self._filenames)) + " documents:\nFailed: " + str(failed) + "\nSucceed: " + str(succeed))
 def _loadDirectoryMultipleShort(self):
     directory = QtGui.QFileDialog.getExistingDirectory()
     logger.debug(directory)
     self._filenames = [directory+"/"+f for f in listdir(directory)]
     self.ui.loadededFilesShortTextEdit.clear()
     if len(self._filenames) < 1:
         logger.info("Please, select files before parsing")
         return
     failed = 0
     succeed = 0
     for filename in self._filenames:
         logger.info("Parsing file " + filename.split('/')[-1] + " from TeX")
         try:
             self._writeups.append(ShortWriteUp.parseFromTex(filename))
             self.ui.loadededFilesShortTextEdit.insertPlainText(filename.split('/')[-1]+"\n")
             succeed += 1
             logger.info(self._writeups[-1])
             logger.info("Parsing done...")
         except Exception as ex:
             failed += 1
             logger.debug(str(ex))
             logger.info("Error in parsing the document. Please, select a file with the correct latex structure")
             #TODO the error chain for getting a message to the user
     logger.info("For " + str(len(self._filenames)) + " documents:\nFailed: " + str(failed) + "\nSucceed: " + str(succeed))
Exemple #10
0
def testSinglePaper():
    doc = BeautifulSoup(auxTools.getFixedHTML("http://goossens.web.cern.ch/goossens/wwwdir/shortwrupsdir/b002/top.html"), 'html.parser')
    proc = ShortWriteUp()
    proc.loadFromHTML(doc)
    print(proc)