3636
3737# importing modules from Python library
3838import copy
39- import re
4039import os
4140import sys
4241from pprint import pprint
7271# the file containing the Sage-Combinat bibliography formatted in HTML
7372html_combinat = os .path .join (PWD , "publications-combinat.html" )
7473# upstream version of the BibTeX database of Sage-Combinat
75- #bibtex_sage_combinat = "http://combinat.sagemath.org/hgwebdir.cgi/misc/raw-file/tip/articles/Sage-Combinat.bib"
74+ # bibtex_sage_combinat = "http://combinat.sagemath.org/hgwebdir.cgi/misc/raw-file/tip/articles/Sage-Combinat.bib"
7675# the file containing the MuPAD-Combinat BibTeX database
7776publications_mupad = os .path .join (PWD , "MuPAD-Combinat.bib" )
7877# the file containing the MuPAD publications list formatted in HTML
7978html_mupad = os .path .join (PWD , "publications-mupad.html" )
8079# MathSciNet
81- publications_mathscinet = os .path .join (PWD , ' mathscinet.bib' )
82- html_mathscinet = os .path .join (PWD , ' publications-mathscinet.html' )
80+ publications_mathscinet = os .path .join (PWD , " mathscinet.bib" )
81+ html_mathscinet = os .path .join (PWD , " publications-mathscinet.html" )
8382
8483# Stuff relating to file permissions.
8584# whether we should change the permissions of a file
@@ -316,17 +315,18 @@ def extract_publication(entry_dict):
316315 for attribute in entry_dict .fields .keys ():
317316 publication_dict .setdefault (
318317 str (attribute ).strip ().lower (),
319- unicode (entry_dict .fields [attribute ]).strip ())
318+ unicode (entry_dict .fields [attribute ]).strip (),
319+ )
320320 # The author field is a required field in BibTeX format.
321321 # Extract author names.
322322 authors_str = ""
323323 authors_list = entry_dict .persons ["author" ]
324324 authors_str = str (unicode (plain (authors_list [0 ]).format ()))
325325 if len (authors_list ) > 1 :
326326 for author in authors_list [1 :]:
327- authors_str = u "" .join (
328- [authors_str , " and " ,
329- str ( unicode ( plain ( author ). format ()))] )
327+ authors_str = "" .join (
328+ [authors_str , " and " , str ( unicode ( plain ( author ). format ()))]
329+ )
330330 authors_str = authors_str .replace ("<nbsp>" , " " )
331331 publication_dict .setdefault ("author" , authors_str )
332332 # The editor field is an optional field in BibTeX format.
@@ -337,10 +337,9 @@ def extract_publication(entry_dict):
337337 editors_str = str (unicode (plain (editors_list [0 ]).format ()))
338338 if len (editors_list ) > 1 :
339339 for editor in editors_list [1 :]:
340- editors_str = u"" .join ([
341- editors_str , " and " ,
342- str (unicode (plain (editor ).format ()))
343- ])
340+ editors_str = "" .join (
341+ [editors_str , " and " , str (unicode (plain (editor ).format ()))]
342+ )
344343 editors_str = editors_str .replace ("<nbsp>" , " " )
345344 publication_dict .setdefault ("editor" , editors_str )
346345 return publication_dict
@@ -370,10 +369,7 @@ def filter_undergraduate_theses(publications):
370369 undergraduate_theses .append (item )
371370 else :
372371 preprints .append (item )
373- return {
374- "preprints" : preprints ,
375- "undergraduatetheses" : undergraduate_theses
376- }
372+ return {"preprints" : preprints , "undergraduatetheses" : undergraduate_theses }
377373
378374
379375def format_articles (articles ):
@@ -400,17 +396,19 @@ def format_articles(articles):
400396 try :
401397 htmlstr = "" .join ([format_names (article ["author" ]), ". " ])
402398 htmlstr = "" .join ([htmlstr , html_title (article )])
403- aj = article .get ("journal" , article .get (' journaltitle' ))
399+ aj = article .get ("journal" , article .get (" journaltitle" ))
404400 htmlstr = "" .join ([htmlstr , aj , ", " ])
405401 for attribute in optional_attributes :
406402 if attribute in article :
407403 htmlstr = "" .join (
408- [htmlstr , attribute , " " , article [attribute ], ", " ])
409- ay = article .get ("year" , article .get ('date' ))
404+ [htmlstr , attribute , " " , article [attribute ], ", " ]
405+ )
406+ ay = article .get ("year" , article .get ("date" ))
410407 htmlstr = "" .join ([htmlstr , ay , "." ])
411408 formatted_articles .append (htmlstr .strip ())
412409 except Exception as ex :
413410 from pprint import pprint
411+
414412 pprint (article )
415413 raise ex
416414 return list (map (replace_special , formatted_articles ))
@@ -472,14 +470,14 @@ def format_collections(collections):
472470 htmlstr = "" .join ([htmlstr , html_title (entry )])
473471 if "editor" in entry :
474472 htmlstr = "" .join (
475- [htmlstr , "In " ,
476- format_names ( entry [ "editor" ]), " (ed.). " ] )
473+ [htmlstr , "In " , format_names ( entry [ "editor" ]), " (ed.). " ]
474+ )
477475 htmlstr = "" .join ([htmlstr , entry ["booktitle" ], ". " ])
478476 if "publisher" in entry :
479477 htmlstr = "" .join ([htmlstr , entry ["publisher" ], ", " ])
480478 if "pages" in entry :
481479 htmlstr = "" .join ([htmlstr , "pages " , entry ["pages" ], ", " ])
482- ay = entry .get ("year" , entry .get (' date' ))
480+ ay = entry .get ("year" , entry .get (" date" ))
483481 htmlstr = "" .join ([htmlstr , ay , "." ])
484482 formatted_entries .append (htmlstr .strip ())
485483 return list (map (replace_special , formatted_entries ))
@@ -500,7 +498,7 @@ def format_masterstheses(masterstheses):
500498 A list of Master's theses all of which are formatted in HTML
501499 suitable for displaying on websites.
502500 """
503- return format_theses (masterstheses , ' Masters thesis' )
501+ return format_theses (masterstheses , " Masters thesis" )
504502
505503
506504def format_miscs (miscs , thesis = False ):
@@ -536,9 +534,9 @@ def format_miscs(miscs, thesis=False):
536534 note = entry ["note" ]
537535 # handle the case: note = {<url> Bachelor thesis},
538536 if "http://" in note :
539- note = note [note .find (" " ):].strip ()
537+ note = note [note .find (" " ) :].strip ()
540538 htmlstr = "" .join ([htmlstr , note , ", " ])
541- y = entry .get ("year" , entry .get (' date' ))
539+ y = entry .get ("year" , entry .get (" date" ))
542540 htmlstr = "" .join ([htmlstr , y , "." ])
543541 formatted_miscs .append (htmlstr .strip ())
544542 except Exception as ex :
@@ -573,6 +571,7 @@ def format_names(names) -> str:
573571 formatted_names [i ] = "" .join ([formatted_names [i ], ", " ])
574572 return "" .join (formatted_names )
575573
574+
576575def format_theses (theses : list [dict [str , str ]], thesis_type : str ) -> list [str ]:
577576 r"""
578577 Format each thesis in HTML format.
@@ -594,24 +593,23 @@ def format_theses(theses: list[dict[str, str]], thesis_type: str) -> list[str]:
594593 formatted_theses : list [str ] = []
595594 for thesis in theses :
596595 try :
597- htmlstr = '' .join ([format_names (thesis ['author' ]), '. ' ])
598- htmlstr = '' .join ([htmlstr , html_title (thesis )])
599-
600- htmlstr = '' .join ([htmlstr , f'{ thesis .get ('type' , thesis_type )} , ' ])
596+ htmlstr = format_names (thesis ["author" ]) + ". "
597+ htmlstr += html_title (thesis )
601598
602- ts = thesis [ 'school' ]
603- htmlstr = '' . join ([ htmlstr , ts , ', ' ])
599+ htmlstr + = thesis . get ( "type" , thesis_type ) + ", "
600+ htmlstr += thesis [ "school" ] + ", "
604601
605- if ' address' in thesis :
606- htmlstr = '' . join ([ htmlstr , thesis [' address' ], ', ' ])
602+ if " address" in thesis :
603+ htmlstr += thesis [" address" ] + ", "
607604
608- htmlstr = '' . join ([ htmlstr , thesis [' year' ], '.' ])
605+ htmlstr += thesis [" year" ] + "."
609606 formatted_theses .append (htmlstr .strip ())
610607 except Exception as ex :
611608 pprint (thesis )
612609 raise ex
613610 return list (map (replace_special , formatted_theses ))
614611
612+
615613def format_phdtheses (phdtheses ):
616614 r"""
617615 Format each PhD thesis in HTML format.
@@ -627,7 +625,7 @@ def format_phdtheses(phdtheses):
627625 A list of PhD theses all of which are formatted in HTML
628626 suitable for displaying on websites.
629627 """
630- return format_theses (phdtheses , ' PhD thesis' )
628+ return format_theses (phdtheses , " PhD thesis" )
631629
632630
633631def format_techreports (techreports ):
@@ -655,8 +653,9 @@ def format_techreports(techreports):
655653 htmlstr = "" .join ([htmlstr , report ["address" ], ", " ])
656654 if "number" in report :
657655 htmlstr = "" .join (
658- [htmlstr , "technical report number " , report ["number" ], ", " ])
659- y = report .get ("year" , report .get ('date' ))
656+ [htmlstr , "technical report number " , report ["number" ], ", " ]
657+ )
658+ y = report .get ("year" , report .get ("date" ))
660659 htmlstr = "" .join ([htmlstr , y , "." ])
661660 formatted_reports .append (htmlstr .strip ())
662661 return list (map (replace_special , formatted_reports ))
@@ -684,8 +683,8 @@ def format_proceedings(proceedings):
684683 htmlstr = "" .join ([htmlstr , html_title (article )])
685684 if "editor" in article :
686685 htmlstr = "" .join (
687- [htmlstr , "In " ,
688- format_names ( article [ "editor" ]), " (ed.). " ] )
686+ [htmlstr , "In " , format_names ( article [ "editor" ]), " (ed.). " ]
687+ )
689688 htmlstr = "" .join ([htmlstr , article ["booktitle" ], ". " ])
690689 if "publisher" in article :
691690 htmlstr = "" .join ([htmlstr , article ["publisher" ], ", " ])
@@ -698,7 +697,7 @@ def format_proceedings(proceedings):
698697 htmlstr = "" .join ([htmlstr , "Pages " , article ["pages" ], ", " ])
699698 else :
700699 htmlstr = "" .join ([htmlstr , "pages " , article ["pages" ], ", " ])
701- ay = article .get ("year" , article .get (' date' ))
700+ ay = article .get ("year" , article .get (" date" ))
702701 htmlstr = "" .join ([htmlstr , ay , "." ])
703702 formatted_proceedings .append (htmlstr .strip ())
704703 return list (map (replace_special , formatted_proceedings ))
@@ -727,7 +726,7 @@ def format_unpublisheds(unpublisheds):
727726 htmlstr = "" .join ([htmlstr , html_title (entry )])
728727 if "month" in entry :
729728 htmlstr = "" .join ([htmlstr , entry ["month" ], ", " ])
730- y = entry .get (' year' , entry .get (' date' ))
729+ y = entry .get (" year" , entry .get (" date" ))
731730 htmlstr = "" .join ([htmlstr , y , "." ])
732731 formatted_entries .append (htmlstr .strip ())
733732 except Exception as ex :
@@ -764,7 +763,7 @@ def html_title(publication):
764763 title = publication ["title" ]
765764 if url != "" :
766765 if ("http://" in url ) or ("https://" in url ):
767- return "" .join ([" <a href=\" " , url , " \" >" , title , "</a>" , ". " ])
766+ return "" .join ([' <a href="' , url , '">' , title , "</a>" , ". " ])
768767 # handle the case where no URL is provided or the "note" field doesn't
769768 # contain a URL
770769 return "" .join ([title , ". " ])
@@ -818,27 +817,32 @@ def macro(name, sorted_index, papers):
818817 # Sort the publication items. Journal articles, items in collections,
819818 # and proceedings papers are grouped in one section. Sort these.
820819 papers = articles + collections + proceedings + techreports
821- sorted_index = sort_publications (publications ["articles" ] +
822- publications ["incollections" ] +
823- publications ["inproceedings" ] +
824- publications ["techreports" ])
820+ sorted_index = sort_publications (
821+ publications ["articles" ]
822+ + publications ["incollections" ]
823+ + publications ["inproceedings" ]
824+ + publications ["techreports" ]
825+ )
825826 # insert the new list of articles
826827 htmlcontent += macro ("papers" , sorted_index , papers )
827828
828829 # Sort the list of theses. These include PhD, Master's, and undergraduate
829830 # theses.
830831 theses = masterstheses + phdtheses + undergradtheses
831- sorted_index = sort_publications (publications ["masterstheses" ] +
832- publications ["phdtheses" ] +
833- miscs ["undergraduatetheses" ])
832+ sorted_index = sort_publications (
833+ publications ["masterstheses" ]
834+ + publications ["phdtheses" ]
835+ + miscs ["undergraduatetheses" ]
836+ )
834837 # insert the new list of theses
835838 htmlcontent += macro ("thesis" , sorted_index , theses )
836839
837840 # Sort the list of books. These include both published books and
838841 # unpublished manuscripts.
839842 books_list = books + unpublisheds
840- sorted_index = sort_publications (publications ["books" ] +
841- publications ["unpublisheds" ])
843+ sorted_index = sort_publications (
844+ publications ["books" ] + publications ["unpublisheds" ]
845+ )
842846 htmlcontent += macro ("books" , sorted_index , books_list )
843847
844848 # Sort the list of preprints.
@@ -908,8 +912,9 @@ def process_database(dbfilename):
908912 try :
909913 pub_list .append (extract_publication (bibdb .entries [key ]))
910914 except Exception as ex :
911- #raise ex
915+ # raise ex
912916 import json
917+
913918 print (key )
914919 print (json .dumps (bibdb .entries [key ]))
915920 raise ex
@@ -923,7 +928,7 @@ def process_database(dbfilename):
923928 "miscs" : misc ,
924929 "phdtheses" : phdthesis ,
925930 "techreports" : techreport ,
926- "unpublisheds" : unpublished
931+ "unpublisheds" : unpublished ,
927932 }
928933
929934
@@ -1108,14 +1113,13 @@ def sort_by_name(publications):
11081113 """
11091114 NAME_INDEX = 0
11101115 POSITION_INDEX = 1
1111- author_names = [(publications [i ]["author" ], i )
1112- for i in range ( len ( publications ))]
1113- last_names = [ (surname (author_names [i ][NAME_INDEX ]), i )
1114- for i in range ( len ( author_names )) ]
1116+ author_names = [(publications [i ]["author" ], i ) for i in range ( len ( publications ))]
1117+ last_names = [
1118+ (surname (author_names [i ][NAME_INDEX ]), i ) for i in range ( len ( author_names ) )
1119+ ]
11151120 sorted_names = sorted (last_names )
11161121 return [
1117- publications [sorted_names [i ][POSITION_INDEX ]]
1118- for i in range (len (sorted_names ))
1122+ publications [sorted_names [i ][POSITION_INDEX ]] for i in range (len (sorted_names ))
11191123 ]
11201124
11211125
@@ -1138,14 +1142,15 @@ def sort_by_year(publications):
11381142 pairs. Each publication year is a four-digit year. The publications list
11391143 contains items published during that year.
11401144 """
1141- item_years = [(publications [i ].get ("year" , publications [i ].get ('date' )), i )
1142- for i in range (len (publications ))]
1145+ item_years = [
1146+ (publications [i ].get ("year" , publications [i ].get ("date" )), i )
1147+ for i in range (len (publications ))
1148+ ]
11431149 sorted_years = sorted (item_years )
11441150 items_dict = {}
11451151 for year , item in sorted_years :
11461152 if year in items_dict :
1147- items_dict .setdefault (year ,
1148- items_dict [year ].append (publications [item ]))
1153+ items_dict .setdefault (year , items_dict [year ].append (publications [item ]))
11491154 else :
11501155 items_dict .setdefault (year , [publications [item ]])
11511156 return items_dict
@@ -1182,6 +1187,7 @@ def surname(name):
11821187 # os.system("rm " + publications_combinat)
11831188 # os.system("wget " + bibtex_sage_combinat)
11841189 import sys
1190+
11851191 if len (sys .argv ) >= 2 :
11861192 what = sys .argv [1 ]
11871193 else :
0 commit comments