-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# bib-combiner | ||
# bib-combiner | ||
|
||
A small python tool for combining multiple .bib files and removing duplicates by their IDs (ID: the string used for citation in lalex.) | ||
|
||
## Usage | ||
```bash | ||
python bib_combiner.py bib1.bib bib2.bib bib3.bib .bib | ||
``` | ||
output is named `final.bib`. | ||
|
||
## Requirements | ||
see `requiremetns.txt` generated by [pipreqs](https://pypi.org/project/pipreqs/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import sys | ||
import bibtexparser | ||
|
||
from bibtexparser.bwriter import BibTexWriter | ||
from bibtexparser.bibdatabase import BibDatabase | ||
|
||
if __name__ == "__main__": | ||
bibtex_list = sys.argv[1:] | ||
print(bibtex_list) | ||
|
||
db_final = BibDatabase() | ||
db_final.entries = [] | ||
|
||
bib_ids = [] | ||
bib_total = 0 | ||
bib_sum = 0 | ||
duplicate_num = 0 | ||
|
||
for bibtex in bibtex_list: | ||
with open(bibtex, 'r') as bibtex_file: | ||
bib_database = bibtexparser.load(bibtex_file) | ||
for bib_dict in bib_database.entries: | ||
bib_total += 1 | ||
if bib_dict['ID'] not in bib_ids: | ||
bib_sum += 1 | ||
bib_ids.append(bib_dict['ID']) | ||
db_final.entries.append(bib_dict) | ||
else: | ||
duplicate_num += 1 | ||
|
||
print(f'Total: {bib_total}, Duplicate:{duplicate_num}, Final:{bib_sum}') | ||
|
||
with open('final.bib', 'w') as bibtex_file: | ||
bibtexparser.dump(db_final, bibtex_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bibtexparser==1.2.0 | ||
python==3.9 |