publist

managing my list of publications, talks, reviews
git clone https://a3nm.net/git/publist/
Log | Files | Refs | README | LICENSE

make_talks_html.py (18155B)


      1 #!/usr/bin/python3
      2 
      3 import os
      4 from parserec import parse, stz, getvenue, isurlrel, getyear, endswithpunct, authorname, talk_types, stopwords
      5 import datetime
      6 import sys
      7 
      8 if __name__ == '__main__':
      9     now = datetime.datetime.now()
     10     dnow = (now.year, now.month, now.day)
     11 
     12     # http://stackoverflow.com/a/1432949
     13     abspath = os.path.abspath(__file__)
     14     dname = os.path.dirname(abspath)
     15     os.chdir(dname)
     16 
     17     # arguments are: authors venues publis talks
     18     authorsfn, venuesfn, publisfn, talksfn = sys.argv[1:]
     19 
     20     authorsz = dict((x['id'], x) for x in parse(authorsfn))
     21     venuesz = dict((x['id'], x) for x in parse(venuesfn))
     22 
     23 def mkyearsep(lastyear, year):
     24     s = ''
     25     if lastyear:
     26         s += '</ul>\n\n'
     27     s += ('## %d\n\n<ul>' % year)
     28     return s
     29 
     30 def mklink(text, obj, pref=''):
     31     if pref + 'url' in obj.keys():
     32         return '<a href="%s">%s</a>' % (obj[pref + 'url'], text)
     33     return text
     34 
     35 def makeauthor(aid, links=True):
     36     global authorsz
     37     aid = ''.join(c for c in aid if c.isalnum())
     38     a = authorsz[aid]
     39     if links:
     40         return mklink(authorname(a), a)
     41     else:
     42         return authorname(a)
     43 
     44 def maketitle(publi, prefix):
     45     urltext = ''
     46     if 'url' in publi.keys():
     47         urltext = ' href="%s"' % (prefix + publi['url'])
     48     return ('<a class="papertitle"%s>%s</a>%s<br/>'
     49             % (urltext, publi['title'], "" if endswithpunct(publi) else "."))
     50 
     51 def makevenue2(venue, lang, typ, url, issue, links=True, hidden=False):
     52     global stz
     53     urltext = ''
     54     if url:
     55         urltext = ' href="%s"' % url
     56     issuetext = ''
     57     if len(issue) > 0:
     58         issuetext = ', %s' % issue
     59     if hidden and venue not in stz['submitted'].values() and typ != None:
     60         year = None
     61         try:
     62             year = venue[-4:]
     63         except IndexError:
     64             pass
     65         if year.isdigit() and len(issuetext) == 0:
     66             issuetext = ', %s' % year
     67         return (stz['published at non oa'][lang] % stz[typ][lang]
     68         + issuetext + 
     69         ' <a href="/work/research/openaccess/#PublishNonOA">' +
     70         stz['oaexplain'][lang] + '</a>'
     71         )
     72     if len(urltext) > 0 and links:
     73         return ('<a%s>%s</a>%s' % (urltext, venue, issuetext))
     74     return (venue + issuetext)
     75 
     76 def makevenue(publi, lang, links=True, hidenonoa=False):
     77     global venuesz
     78     venue, _, typ, url, issue, oa, keywords = getvenue(publi, lang, venuesz)
     79     if venue == 'Draft':
     80         return venue
     81     return makevenue2(venue, lang, typ, url, issue, links=links, hidden=((not oa) and hidenonoa))
     82 
     83 def makesuppl(publi, lang, ismain=False):
     84     global stz
     85     global authorsz
     86     l = []
     87     if 'conferenceversion' in publi.keys() and not ismain:
     88         l.append('<a href="%s">%s</a>' %
     89                 ("#" + publi['conferenceversion'],
     90                     stz['conferenceversion'][lang]))
     91     if 'journalversion' in publi.keys() and not ismain:
     92         l.append('<a href="%s">%s</a>' %
     93                 ("#" + publi['journalversion'],
     94                     stz['journalversion'][lang]))
     95     for key in ['slides', 'slideslong', 'poster', 'video', 'videoplatform', 'code']:
     96         if key in publi.keys():
     97 
     98             # case of videoplatform
     99             if key == 'videoplatform' and 'video' in publi.keys():
    100                     continue # already handled with video
    101             if key == 'videoplatform' and 'video' not in publi.keys():
    102                 s = stz['video'][lang]
    103                 if 'videoauthor' in publi.keys():
    104                     raw_author = publi['videoauthor']
    105                     author_suffix = " %s %s" % (stz['by'][lang], (' ' + stz['and'][lang] + ' ').join(makeauthor(x) for
    106                         x in raw_author.split(' ')))
    107                 s += author_suffix
    108                 s += (' %s <a href="%s">%s</a>' %
    109                         (stz['on'][lang], publi['videoexternal'],
    110                         publi['videoplatform']))
    111                 l.append(s)
    112                 continue
    113 
    114             if key == 'video' and 'videoplatform' in publi.keys():
    115                 s = stz['video'][lang]
    116             else:
    117                 s = '<a href="%s">%s</a>' % (publi[key], stz[key][lang])
    118             if key + 'author' in publi.keys():
    119                 raw_author = publi[key + 'author']
    120                 s += " %s %s" % (stz['by'][lang], (' ' + stz['and'][lang] + ' ').join(makeauthor(x) for
    121                     x in raw_author.split(' ')))
    122             if key == 'video' and 'videoplatform2' in publi.keys():
    123                 s += (' %s <a href="%s">%s</a> %s <a href="%s">%s</a> %s <a href="%s">%s</a>' %
    124                         (stz['on'][lang], publi['videoexternal'],
    125                         publi['videoplatform'],
    126                         stz['oron'][lang], publi['videoexternal2'],
    127                         publi['videoplatform2'],
    128                         stz['orin'][lang],
    129                         publi['video'], stz['direct download'][lang]))
    130             elif key == 'video' and 'videoplatform' in publi.keys():
    131                 s += (' %s <a href="%s">%s</a> %s <a href="%s">%s</a>' %
    132                         (stz['on'][lang], publi['videoexternal'],
    133                         publi['videoplatform'], stz['orin'][lang],
    134                         publi['video'], stz['direct download'][lang]))
    135 
    136             l.append(s)
    137     if 'errata' in publi.keys():
    138         daclass = "errata"
    139         link = "/publications/"
    140         if lang == 'fr':
    141             link += "index.html"
    142         msg = "errata"
    143         if lang == 'fr':
    144             msg = "erreurs identifiées (en anglais)"
    145         if publi['errata'] == 'minor':
    146             msg = "minor errata"
    147             if lang == 'fr':
    148                 msg = "erreurs mineures identifiées (en anglais)"
    149             daclass = "errata_minor"
    150         s = '<a class="%s" href="%s#%s_errata">%s</a>' % (daclass, link, publi['id'], msg)
    151         l.append(s)
    152 
    153     misck = 'misc' + lang 
    154     if misck in publi.keys():
    155         l.append(publi[misck])
    156     elif lang == "en" and 'misc' in publi.keys():
    157         l.append(publi['misc'])
    158     return ', '.join(l)
    159 
    160 def maketalktitle(talk, prefix, lang):
    161     urltext = ''
    162     if 'url' in talk.keys():
    163         urltext = ' href="%s"' % (prefix + talk['url'])
    164     title = talk['title']
    165     localk = 'title' + lang
    166     if localk in talk.keys():
    167         # override for language-specific title
    168         title = talk[localk]
    169     return ('<a%s>%s</a>%s<br/>' % (urltext, title, "" if endswithpunct(talk) else "."))
    170 
    171 def findfrom(talk, venueo, key, items, lang):
    172     lkey = key + lang
    173     if lkey in talk.keys():
    174         items.append(mklink(talk[lkey], talk, key))
    175     elif key in talk.keys():
    176         items.append(mklink(talk[key], talk, key))
    177     elif venueo and lkey in venueo.keys():
    178         items.append(mklink(venueo[lkey], venueo, key))
    179     elif venueo and key in venueo.keys():
    180         items.append(mklink(venueo[key], venueo, key))
    181 
    182 if __name__ == '__main__':
    183     # write publication lists
    184     for lang in ['en', 'fr']:
    185         fmain = open('publis_main.html.' + lang, 'w')
    186         fall = open('publis_all.html.' + lang, 'w')
    187         lastyear = None
    188         doiset = set()
    189         urlset = set()
    190         for publi in parse(publisfn):
    191             print(publi['id'])
    192             year = getyear(publi)
    193 
    194             # all publis should have a URL, but sometimes they don't
    195             assert('url' in publi.keys())
    196             if publi['url'].lower() == 'none':
    197                 del publi['url']
    198             # no duplicate URLs
    199             if 'url' in publi.keys():
    200                 url = publi['url']
    201                 if (url in urlset):
    202                     print("ERROR duplicate url for %s" % publi['id'], file=sys.stderr)
    203                 assert(url not in urlset)
    204                 urlset.add(url)
    205 
    206             # all publis should have a DOI, but sometimes they don't
    207             # except if wrong types
    208             if ('type' not in publi.keys() or publi['type'] not in ['phdthesis',
    209                     'patent', 'mscthesis', 'note', 'habilitationthesis']) and ('status' not in
    210                             publi.keys() or publi['status'] not in
    211                             ['submitted', 'draft', 'toappear']):
    212                 print(publi)
    213                 assert('doi' in publi.keys())
    214             if 'doi' in publi.keys() and publi['doi'].lower() == 'none':
    215                 del publi['doi']
    216             # no duplicate DOIs
    217             if 'doi' in publi.keys():
    218                 doi = publi['doi']
    219                 if (doi in doiset):
    220                     print("ERROR duplicate DOI for %s" % publi['id'], file=sys.stderr)
    221                 assert(doi not in doiset)
    222                 doiset.add(doi)
    223 
    224             outlist = set()
    225             outlist.add(fall)
    226             if not 'venue' in publi.keys():
    227                 outlist.add(fmain)
    228             if 'main' in publi.keys() and publi['main'] != 'no':
    229                 assert(publi['main'] == 'yes')
    230                 outlist.add(fmain)
    231 
    232             for fout in outlist:
    233                 myid = publi['id']
    234                 myoldid = None
    235                 try:
    236                     myoldid = publi['oldid']
    237                 except KeyError:
    238                     pass
    239                 authors = publi['authors'].split(' ')
    240                 reviewed = False
    241                 if 'reviewed' in publi.keys() and publi['reviewed'] != 'no':
    242                     assert(publi['reviewed'] == 'yes')
    243                     reviewed = True
    244                 prefix = ""
    245                 if fout == fmain:
    246                     if 'url' in publi.keys() and isurlrel(publi['url']):
    247                         prefix = "publications/"
    248                 if fout == fall:
    249                     if year != lastyear:
    250                         print(mkyearsep(lastyear, year), file=fout)
    251                         lastyear = year
    252                 print('<li id="%s">' % myid, file=fout)
    253                 if myoldid:
    254                     for myoldid1 in myoldid.split(' '):
    255                         print('<a id="%s"></a>' % myoldid1, file=fout)
    256                 print(',\n'.join(makeauthor(a) for a in authors) + '.<br/>',
    257                         file=fout)
    258                 print(maketitle(publi, prefix), file=fout)
    259                 print(makevenue(publi, lang, hidenonoa=(fout == fmain)) + '.', file=fout, end="")
    260                 hadbr = False
    261                 if 'type' in publi.keys() and publi['type'] in ['demo',
    262                         'spotlight', 'shortpaper', 'posterpaper']:
    263                     print(' ' + stz[publi['type']][lang] + '.', file=fout, end='')
    264                 suppl = makesuppl(publi, lang, True if fout == fmain else False)
    265                 if len(suppl) > 0:
    266                     hadbr = True
    267                     print("\n", file=fout, end="")
    268                     print('[%s]' % suppl, file=fout, end="")
    269                 if 'award' in publi.keys():
    270                     awardk = 'award' + lang 
    271                     val = publi['award']
    272                     if awardk in publi.keys():
    273                         val = publi[awardk]
    274                     print('. %s.' % val, file=fout, end="")
    275                 if fout == fall:
    276                     if not reviewed:
    277                         print(' (*)', file=fout, end="")
    278                 print('\n</li>', file=fout)
    279 
    280         print('</ul>', file=fall)
    281         fall.close()
    282         fmain.close()
    283 
    284     # write text publication list
    285     for lang in ['en', 'fr']:
    286         ftext = open('publis_' + lang + ".txt", 'w')
    287         # lastyear = None
    288         for publi in parse(publisfn):
    289             print(publi['id'])
    290             year = getyear(publi)
    291 
    292             # all publis should have a URL, but sometimes they don't
    293             assert('url' in publi.keys())
    294             if publi['url'].lower() == 'none':
    295                 del publi['url']
    296             # not re-doing the DOI check from above
    297             if 'doi' in publi.keys() and publi['doi'].lower() == 'none':
    298                 del publi['doi']
    299 
    300             outlist = set()
    301             if 'venue' in publi.keys():
    302                 outlist.add(fall)
    303             else:
    304                 outlist.add(fmain)
    305             if 'main' in publi.keys() and publi['main'] != 'no':
    306                 assert(publi['main'] == 'yes')
    307                 outlist.add(fmain)
    308 
    309             myid = publi['id']
    310             myoldid = None
    311             try:
    312                 myoldid = publi['oldid']
    313             except KeyError:
    314                 pass
    315             authors = publi['authors'].split(' ')
    316             reviewed = False
    317             if 'reviewed' in publi.keys() and publi['reviewed'] != 'no':
    318                 assert(publi['reviewed'] == 'yes')
    319                 reviewed = True
    320             prefix = ""
    321             if 'url' in publi.keys() and isurlrel(publi['url']):
    322                 prefix = "https://a3nm.net/publications/"
    323             print(', '.join(makeauthor(a, links=False) for a in authors),
    324                     file=ftext)
    325             print(publi['title'], file=ftext)
    326             if 'status' in publi.keys() and publi['status'] == 'submitted':
    327                 print('Preprint', file=ftext)
    328             else:
    329                 print(makevenue(publi, lang, links=False), file=ftext, end="")
    330                 if not reviewed:
    331                     assert (lang in ['en', 'fr'])
    332                     if lang == 'en':
    333                         print(' (not peer-reviewed)', file=ftext)
    334                     else: # lang == 'fr':
    335                         print(' (non relu par les pairs)', file=ftext)
    336                 else:
    337                     print("", file=ftext)
    338             if 'url' in publi.keys():
    339                 print(prefix + publi['url'] if isurlrel(publi['url']) else
    340                         publi['url'], file=ftext)
    341             print("", file=ftext)
    342 
    343         ftext.close()
    344 
    345 
    346 
    347     # write talks list
    348 
    349     # num of last talks
    350     LIMIT = 5
    351 
    352     for lang in ['en', 'fr']:
    353         flast = open('talks_last.html.' + lang, 'w')
    354         fall = open('talks_all.html.' + lang, 'w')
    355         lastdate = None
    356         lastyear = None
    357         num_per_day = 1
    358         in_last = 0
    359         for talk in parse(talksfn):
    360             date = talk['date']
    361             assert(len(date) == 4 + 1 + 2 + 1 + 2)
    362             print(date)
    363             year = int(date[:4])
    364             assert(date[4] == '-')
    365             month = int(date[5:7])
    366             assert(date[7] == '-')
    367             day = int(date[8:10])
    368             datet = (year, month, day)
    369             # file should be in sorted order!
    370             assert(not lastdate or datet <= lastdate)
    371             if lastdate == datet:
    372                 num_per_day += 1
    373             else:
    374                 num_per_day = 1
    375             lastdate = datet
    376 
    377             outlist = set()
    378             outlist.add(fall)
    379             # if dnow >= datet:
    380             #     # past talk
    381             #     outlist.add(fall)
    382             if dnow < datet:
    383                 # future talk
    384                 outlist.add(flast)
    385             if in_last < LIMIT:
    386                 in_last += 1
    387                 outlist.add(flast)
    388 
    389             for fout in outlist:
    390                 if fout == fall:
    391                     if year != lastyear:
    392                         print(mkyearsep(lastyear, year), file=fout)
    393                         lastyear = year
    394                 prefix = ""
    395                 if fout == flast:
    396                     if 'url' in talk.keys() and isurlrel(talk['url']):
    397                         prefix = "work/talks/"
    398 
    399                 venueo = None
    400                 if 'venue' in talk.keys() and talk['venue'] in venuesz.keys():
    401                     venueo = venuesz[talk['venue']]
    402 
    403                 ddate = date
    404                 if num_per_day > 1:
    405                     ddate += ("_%d" % num_per_day)
    406                 print('<li id="t%s">' % ddate, file=fout)
    407                 if 'status' in talk.keys() and talk['status'] == "canceled":
    408                     print ("<del>", file=fout)
    409                 print(maketalktitle(talk, prefix, lang), file=fout)
    410 
    411                 items = []
    412                 if 'type' in talk.keys():
    413                     assert(talk['type'] in talk_types)
    414                     items.append(stz[talk['type']][lang])
    415 
    416                 if 'venue' in talk.keys() or ('venue' + lang) in talk.keys():
    417                     itmvenue = makevenue(talk, lang)
    418                     team = None
    419                     if 'team' in talk.keys():
    420                         team = mklink(talk['team'], talk, 'team')
    421                     if '>$TEAM' in itmvenue:
    422                         # at the beginning, avoid nested links
    423                         team = mklink(talk['team'], talk, 'team')
    424                         itmvenue = itmvenue.replace("$TEAM ", "")
    425                         itmvenue = team + " " + itmvenue
    426                     for stopword in stopwords:
    427                         teamsybm = ' ' + stopword + ' $TEAM'
    428                         if teamsybm + '<' in itmvenue:
    429                             # at the end, avoid nested links
    430                             itmvenue = itmvenue.replace(teamsybm, "")
    431                             itmvenue = itmvenue + " " + stopword + " " + team
    432                     if '$TEAM<' in itmvenue:
    433                         # at the end, avoid nested links
    434                         itmvenue = itmvenue.replace(" $TEAM", "")
    435                         itmvenue = itmvenue + " " + team
    436                     if '$TEAM' in itmvenue:
    437                         itmvenue = itmvenue.replace("$TEAM", team)
    438                     items.append(itmvenue)
    439 
    440                 findfrom(talk, venueo, 'place', items, lang)
    441                 findfrom(talk, venueo, 'location', items, lang)
    442 
    443                 items.append(talk['date'])
    444 
    445                 items[0] = items[0][0].upper() + items[0][1:]
    446 
    447                 print(', '.join(items) + '.', file=fout)
    448                 if 'status' in talk.keys() and talk['status'] == "canceled":
    449                     print ("</del>", file=fout)
    450                 if 'misc' in talk.keys() or 'misc' + lang in talk.keys():
    451                     if 'misc' + lang in talk.keys():
    452                         print('[%s]' % talk['misc'+lang], file=fout)
    453                     else:
    454                         print('[%s]' % talk['misc'], file=fout)
    455                 print('</li>', file=fout)
    456 
    457         print('</ul>', file=fall)
    458         fall.close()
    459         flast.close()
    460