bib2ref: GUI版本已经发布

There is a need to generate a reference list from bibtex which can be used in markdown software such as typora. However, there is no convenient tool to finish this work, and we build a little program to generate it.

GNU General Public License v3.0

Download a GUI version of bib2ref:

Download:https://www.yuhualixin.com/cloud/index.php?share/file&user=1&sid=ebYpfwdi PWD:QfX1L

You can also get this software and source code in my github: https://github.com/lixin555/bib2ref

The site of a old version script of bib2ref: https://www.yuhualixin.com/714.html


This executable program of GUI version is based on pyqt5. If you want to use this software, chromedriver must be installed and variable of environment should be configured on your PC.

Download chromedriver: https://npm.taobao.org/mirrors/chromedriver/

New Feature:

1.support to query reference list via Bing academic server

2.doi mode is provided to query single doi and get its reference

3.add a graphical user interface and this software can be used conveniently

Tutorial:

a.Batch Mode (Default mode)

1.default mode is the batch mode which asks you to get bibtex file (.bib) from Mendeley, Web Of Science, Elsevier, CNKI ...

2.open bib2ref and click "input" button to select your bibtex file. Click "output" button to create a txt file to save data.

3.click "百度学术" or "bing学术" to generate reference list which can be got in the textbox below or your output txt file.

b.DOI Mode

A single doi number can be queried by this mode. You need click "DOI mode" button to switch this mode. Then click "百度学术" or "bing学术" to get reference in the textbox below.

Error Information:

Timeout or There is no data matching with this doi

If you meet this error, it means that there is no data matching with your doi or your internet speed is too slow.

source code:

main.py

import os,sys
import bib2ref,resource_rc
from PyQt5.QtWidgets import QApplication, QMainWindow
from functools import partial
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
mode_num = 1
def input_file(ui):
    try:
        input_path = ui.input_bib()
        ui.lineEdit.setText(str(input_path))
    except:
        pass
def output_file(ui):
    try:
        output_path = ui.output_txt()
        ui.lineEdit_2.setText(str(output_path))
    except:
        pass
def doimode(ui):
    global mode_num
    mode_num = 2
def batchmode(ui):
    global mode_num
    mode_num = 1
def exitgui(ui):
    qapp = QApplication.instance()
    qapp.quit()
def baidu(ui):
    global mode_num
    xpath = "//a[@class='paper_q']"
    try:
        if mode_num == 1:
            input_path = ui.lineEdit.text()
            f = open(input_path, 'r', encoding='UTF-8')
            doi = []
            cite = []
            num = 0
            line = f.readline()
            while line:
                if "doi =" in line:
                    doi.append(line.split('{')[-1].split('}')[0])
                line = f.readline()
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument("--headless")
            chrome_options.add_argument("--disable-gpu")
            chromeDriverPath = 'chromedriver.exe'
            driver = webdriver.Chrome(options=chrome_options, executable_path=chromeDriverPath)
            driver.get('http://xueshu.baidu.com/')
            for i in doi:
                num = num + 1
                try:
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "kw")))
                    driver.find_element_by_id("kw").send_keys(i)
                    driver.find_element_by_id("su").click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sc_quote_bg")))
                    driver.find_element_by_xpath(xpath).click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sc_cit0")))
                    dr = driver.find_element_by_id('sc_cit0')
                    dr.get_attribute('data-original-title')
                    text = "[" + str(num) + "]" + ' ' + dr.text
                except:
                    text = "[" + num +" ] Timeout or There is no data matching with this doi:" + i
                cite.append(text)
                driver.back()
            driver.quit()
            output_path = ui.lineEdit_2.text()
            file_write = open(output_path, 'a', encoding='utf8')
            ui.textBrowser.append("*****Baidu Academic*****")
            for i in cite:
                file_write.writelines(i + '\n')
                ui.textBrowser.append(i)
            file_write.close()
        elif mode_num == 2:
            doi_num = ui.lineEdit_3.text()
            if doi_num == '':
                pass
            else:
                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument("--headless")
                chrome_options.add_argument("--disable-gpu")
                chromeDriverPath = 'chromedriver.exe'
                driver = webdriver.Chrome(options=chrome_options,executable_path=chromeDriverPath)
                driver.get('http://xueshu.baidu.com/')
                try:
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "kw")))
                    driver.find_element_by_id("kw").send_keys(doi_num)
                    driver.find_element_by_id("su").click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sc_quote_bg")))
                    driver.find_element_by_xpath(xpath).click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sc_cit0")))
                    dr = driver.find_element_by_id('sc_cit0')
                    dr.get_attribute('data-original-title')
                    text = "[DOI MODE]" + ' ' + dr.text
                except:
                    text =  "[DOI MODE] Timeout or There is no data matching with this doi:" + doi_num
                driver.quit()
                ui.textBrowser.append("*****Baidu Academic*****")
                ui.textBrowser.append(text)
    except:
        pass
def bing(ui):
    global mode_num
    xpath = "//div[@class='aca_citeStr']"
    locator = ("xpath", "//span[@class='b_floatR']")
    until_text = "GBT7714"
    try:
        if mode_num == 1:
            input_path = ui.lineEdit.text()
            f = open(input_path, 'r', encoding='UTF-8')
            doi = []
            cite = []
            num = 0
            line = f.readline()
            while line:
                if "doi =" in line:
                    doi.append(line.split('{')[-1].split('}')[0])
                line = f.readline()
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument("--headless")
            chrome_options.add_argument("--disable-gpu")
            chromeDriverPath = 'chromedriver.exe'
            driver = webdriver.Chrome(options=chrome_options, executable_path=chromeDriverPath)
            driver.get('https://cn.bing.com/academic')
            for i in doi:
                num = num + 1
                try:
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sb_form_q")))
                    driver.find_element_by_id("sb_form_q").send_keys(i)
                    driver.find_element_by_id("sb_form_go").click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "aca_cref")))
                    driver.find_element_by_id("aca_cref").click()
                    WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element(locator,until_text))
                    dr = driver.find_element_by_xpath(xpath)
                    dr.get_attribute('data-original-title')
                    text = "[" + str(num) + "]" + ' ' + dr.text
                except:
                    text = "[" + num +" ] Timeout or There is no data matching with this doi:" + i
                cite.append(text)
                driver.back()
            driver.quit()
            output_path = ui.lineEdit_2.text()
            file_write = open(output_path, 'a', encoding='utf8')
            ui.textBrowser.append("*****Bing Academic*****")
            for i in cite:
                file_write.writelines(i + '\n')
                ui.textBrowser.append(i)
            file_write.close()
        elif mode_num == 2:
            doi_num = ui.lineEdit_3.text()
            if doi_num == '':
                pass
            else:
                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument("--headless")
                chrome_options.add_argument("--disable-gpu")
                chromeDriverPath = 'chromedriver.exe'
                driver = webdriver.Chrome(options=chrome_options,executable_path=chromeDriverPath)
                driver.get('https://cn.bing.com/academic')
                try:
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sb_form_q")))
                    driver.find_element_by_id("sb_form_q").send_keys(doi_num)
                    driver.find_element_by_id("sb_form_go").click()
                    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "aca_cref")))
                    driver.find_element_by_id("aca_cref").click()
                    WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element(locator, until_text))
                    dr = driver.find_element_by_xpath(xpath)
                    dr.get_attribute('data-original-title')
                    text = "[DOI MODE]" + ' ' + dr.text
                except:
                    text =  "[DOI MODE] Timeout or There is no data matching with this doi:" + doi_num
                driver.quit()
                ui.textBrowser.append("*****Bing Academic*****")
                ui.textBrowser.append(text)
    except:
        pass
if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = bib2ref.Ui_mainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    ui.pushButton.clicked.connect(partial(input_file,ui))
    ui.pushButton_2.clicked.connect(partial(output_file,ui))
    ui.pushButton_4.clicked.connect(partial(exitgui,ui))
    ui.pushButton_3.clicked.connect(partial(bing,ui))
    ui.pushButton_5.clicked.connect(partial(baidu,ui))
    ui.pushButton_6.clicked.connect(partial(doimode,ui))
    ui.pushButton_7.clicked.connect(partial(batchmode,ui))
    sys.exit(app.exec_())

bib2ref.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'bib2ref.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(801, 598)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/bib2ref.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        mainWindow.setWindowIcon(icon)
        mainWindow.setUnifiedTitleAndToolBarOnMac(False)
        self.centralwidget = QtWidgets.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser.setObjectName("textBrowser")
        self.gridLayout.addWidget(self.textBrowser, 4, 0, 1, 1)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 3)
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.gridLayout.addWidget(self.pushButton_2, 2, 2, 1, 1)
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.gridLayout.addWidget(self.pushButton, 1, 2, 1, 1)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.gridLayout.addWidget(self.lineEdit_2, 2, 0, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout.addWidget(self.label_2)
        self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.horizontalLayout.addWidget(self.lineEdit_3)
        self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_6.setMouseTracking(False)
        self.pushButton_6.setAutoFillBackground(False)
        self.pushButton_6.setCheckable(True)
        self.pushButton_6.setAutoRepeat(False)
        self.pushButton_6.setAutoExclusive(True)
        self.pushButton_6.setAutoDefault(False)
        self.pushButton_6.setDefault(False)
        self.pushButton_6.setFlat(False)
        self.pushButton_6.setObjectName("pushButton_6")
        self.horizontalLayout.addWidget(self.pushButton_6)
        self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_7.setCheckable(True)
        self.pushButton_7.setChecked(True)
        self.pushButton_7.setAutoExclusive(True)
        self.pushButton_7.setObjectName("pushButton_7")
        self.horizontalLayout.addWidget(self.pushButton_7)
        self.gridLayout.addLayout(self.horizontalLayout, 3, 0, 1, 1)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setSpacing(7)
        self.verticalLayout.setObjectName("verticalLayout")
        self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
        self.pushButton_5.setSizePolicy(sizePolicy)
        self.pushButton_5.setObjectName("pushButton_5")
        self.verticalLayout.addWidget(self.pushButton_5)
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
        self.pushButton_3.setSizePolicy(sizePolicy)
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout.addWidget(self.pushButton_3)
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
        self.pushButton_4.setSizePolicy(sizePolicy)
        self.pushButton_4.setObjectName("pushButton_4")
        self.verticalLayout.addWidget(self.pushButton_4)
        self.gridLayout.addLayout(self.verticalLayout, 3, 2, 2, 1)
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 801, 26))
        self.menubar.setObjectName("menubar")
        mainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(mainWindow)
        self.statusbar.setObjectName("statusbar")
        mainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(mainWindow)
        QtCore.QMetaObject.connectSlotsByName(mainWindow)

    def retranslateUi(self, mainWindow):
        _translate = QtCore.QCoreApplication.translate
        mainWindow.setWindowTitle(_translate("mainWindow", "bib2ref  From: www.yuhualixin.com"))
        self.label.setText(_translate("mainWindow", "bib2ref: Extract doi form bibtex file to generate a reference list which can be used in markdown."))
        self.pushButton_2.setText(_translate("mainWindow", "Output"))
        self.pushButton.setText(_translate("mainWindow", "Input"))
        self.label_2.setText(_translate("mainWindow", "DOI"))
        self.pushButton_6.setText(_translate("mainWindow", "DOI mode"))
        self.pushButton_7.setText(_translate("mainWindow", "Batch mode"))
        self.pushButton_5.setText(_translate("mainWindow", "百度学术"))
        self.pushButton_3.setText(_translate("mainWindow", "bing学术"))
        self.pushButton_4.setText(_translate("mainWindow", "Exit"))
    def input_bib(self):
        dialog = QtWidgets.QFileDialog()
        dialog.AcceptMode(QtWidgets.QFileDialog.AcceptOpen)
#        dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
        dialog.setNameFilter("Bibtex (*.bib)")
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        if dialog.exec_():
            fileNames = dialog.selectedFiles()
        return fileNames[0]
    def output_txt(self):
        dialog = QtWidgets.QFileDialog()
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
#        dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
        dialog.setNameFilter("txt (*.txt)")
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        if dialog.exec_():
            fileNames = dialog.selectedFiles()
        return fileNames[0]

More information : https://github.com/lixin555/bib2ref

Last modified: 2020年4月10日

Comments

Write a Reply or Comment

Your email address will not be published.