88Requires pandoc
99"""
1010
11- import os
1211import subprocess
1312import sys
13+ from pathlib import Path
1414
1515import biblib .algo
1616import biblib .bib
1717import biblib .messages
18+ import pandas as pd
1819
1920
20- def get_keys_by_year (bibfile ) :
21+ def get_keys_by_year (bibfile : Path ) -> dict [ str , list [ str ]] :
2122 """Get bibtex entry keys as dict by year"""
2223
2324 with open (bibfile ) as f :
@@ -37,10 +38,9 @@ def get_keys_by_year(bibfile):
3738 return by_year
3839
3940
40- def get_sub_bibliography (year , by_year , bibfile ):
41+ def get_sub_bibliography (year , by_year , bibfile : Path ):
4142 """Get HTML bibliography for the given year"""
42-
43- entries = "," .join (["@" + x for x in by_year [year ]])
43+ entries = "," .join ([f"@{ x } " for x in by_year [year ]])
4444 stdin_input = (
4545 f'---\n bibliography: { bibfile } \n nocite: "{ entries } "\n ...\n # { year } '
4646 )
@@ -58,9 +58,9 @@ def get_sub_bibliography(year, by_year, bibfile):
5858
5959
6060def main ():
61- script_path = os . path . dirname ( os . path . realpath ( __file__ ))
62- bibfile = os . path . join ( script_path , "amici_refs.bib" )
63- outfile = os . path . join ( script_path , "references.md" )
61+ script_path = Path ( __file__ ). parent
62+ bibfile = script_path / "amici_refs.bib"
63+ outfile = script_path / "references.md"
6464
6565 by_year = get_keys_by_year (bibfile )
6666 num_total = sum (map (len , by_year .values ()))
@@ -77,6 +77,7 @@ def main():
7777 "?labels=documentation&title=Add+publication"
7878 "&body=AMICI+was+used+in+this+manuscript:+DOI).\n \n "
7979 )
80+ f .write ("\n \n " )
8081 f .write (
8182 """
8283<style>
@@ -86,10 +87,19 @@ def main():
8687</style>\n
8788"""
8889 )
90+
8991 for year in reversed (sorted (by_year .keys ())):
9092 cur_bib = get_sub_bibliography (year , by_year , bibfile )
9193 f .write (cur_bib )
9294
95+ # Save table with citations / year
96+ years = list (sorted (by_year .keys ()))
97+ citations = [len (by_year [year ]) for year in years ]
98+
99+ pd .DataFrame ({"year" : years , "citations" : citations }).to_csv (
100+ script_path / "usage_by_year.csv" , index = False
101+ )
102+
93103
94104if __name__ == "__main__" :
95105 main ()
0 commit comments