Skip to content

Commit

Permalink
update old scripts slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Zaytsev committed Apr 2, 2020
1 parent 4b160dd commit c4ee5dc
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 248 deletions.
14 changes: 9 additions & 5 deletions export-people.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/c/Users/vadim/AppData/Local/Programs/Python/Python35/python
#!/c/Users/vadim/AppData/Local/Programs/Python/Python37-32/python
# -*- coding: utf-8 -*-
#
# a module for exporting LRJ definitions of people to the HTML frontpages
Expand Down Expand Up @@ -154,25 +154,25 @@ def pad(n):
dls = dict2links(persondef)
boxlinks = ''
if 'roles' in persondef.keys():
things = [bykey[r[0]].getIconItem1(r[1]) for r in persondef['roles']]
things = [bykey[r[0]].getIconItem1(r[1]) for r in persondef['roles'] if r[0] in bykey]
dls += '<h3>Facilitated {} volumes:</h3>'.format(len(persondef['roles'])) \
+ '<div class="minibar">' + movein('\n'.join(things)) + '<br style="clear:left"/></div>'
if 'authored' in persondef.keys():
# List of contributions and papers
things = [bykey[p].up().getIconItem1(bykey[p].get('year')) for p in persondef['authored']]
things = [bykey[p].up().getIconItem1(bykey[p].get('year')) for p in persondef['authored'] if p in bykey]
dls += '<h3>Contributed to:</h3><div class="minibar">' \
+ movein('\n'.join(uniq(things))) \
+ '<br style="clear:left"/></div>' \
+ '<h3>Wrote {} papers:</h3>'.format(len(persondef['authored'])) \
+ '<dl class="toc">' \
+ movein('\n'.join([bykey[p].getItem() for p in persondef['authored']])) \
+ movein('\n'.join([bykey[p].getItem() for p in persondef['authored'] if p in bykey])) \
+ '</dl>'
# things = [sleigh.seekByKey(p).getItem() for p in persondef['authored']]
# travelled to...
# NB: code clone of AST::Venue
# cs =
ads = [c.json['address'][-1] \
for c in {bykey[p].up() for p in persondef['authored']} \
for c in {bykey[p].up() for p in persondef['authored'] if p in bykey} \
if 'address' in c.json]
if ads:
clist = {a:ads.count(a) for a in ads}
Expand All @@ -182,6 +182,8 @@ def pad(n):
# collaborated with...
clist = {}
for p in persondef['authored']:
if p not in bykey:
continue
if 'author' in bykey[p].json.keys():
coas = listify(bykey[p].get('author'))
if ' ' in coas:
Expand Down Expand Up @@ -223,6 +225,8 @@ def pad(n):
# examples = {}
allstems = []
for pk in persondef['authored']:
if pk not in bykey:
continue
allstems += bykey[pk].getBareStems()
stems = {stem:allstems.count(stem) for stem in allstems if not ifIgnored(stem)}
stemkeys = sorted(stems.keys(), key=lambda Z: pad(stems[Z])+pad(len(Z))+Z, reverse=True)
Expand Down
2 changes: 1 addition & 1 deletion export-stems.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/c/Users/vadim/AppData/Local/Programs/Python/Python35/python
#!/c/Users/vadim/AppData/Local/Programs/Python/Python37-32/python
# -*- coding: utf-8 -*-
#
# a module for exporting stems/words to the HTML frontpages
Expand Down
8 changes: 6 additions & 2 deletions export-tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/c/Users/vadim/AppData/Local/Programs/Python/Python35/python
#!/c/Users/vadim/AppData/Local/Programs/Python/Python37-32/python
# -*- coding: utf-8 -*-
#
# a module for exporting LRJ definitions of tags to the HTML frontpages
Expand Down Expand Up @@ -86,7 +86,11 @@ def kv2link(k, v):
if x not in tagged:
tagged.append(x)
# read tag definition
tagdef = parseJSON(ienputdir + '/tags/{}.json'.format(key))
p = ienputdir + '/tags/{}.json'.format(key)
if not os.path.exists(p):
print(C.red('Error') + ' opening ' + p)
continue
tagdef = parseJSON(p)
# what to google?
links = []
if 'g' not in tagdef.keys():
Expand Down
287 changes: 148 additions & 139 deletions export-web.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,151 +18,160 @@
name2file = parseJSON(n2f_name) if os.path.exists(n2f_name) else {}
sleigh = Sleigh(corpusdir, name2file)

def nextYear(vvv):
return int(lastSlash(sorted(glob.glob(vvv+'/*'))[-2]))+1

def next_year(vvv):
return int(lastSlash(sorted(glob.glob(vvv + '/*'))[-2])) + 1


def main():
print('{}: {} venues, {} papers\n{}'.format(\
C.purple('BibSLEIGH'),
C.red(len(sleigh.venues)),
C.red(sleigh.numOfPapers()),
C.purple('='*42)))
# generate the index
f = open(outputdir+'/index.html', 'w', encoding='utf-8')
f.write(sleigh.getPage())
f.close()
# generate all individual pages
# if False:
for v in sleigh.venues:
r = C.blue(v.getKey())
f = open(outputdir+'/'+v.getKey()+'.html', 'w', encoding='utf-8')
f.write(v.getPage())
f.close()
if v.brands:
r += '{' + '+'.join([C.blue(b.getKey()) for b in v.brands]) + '}'
for b in v.brands:
f = open(outputdir+'/'+b.getKey()+'.brand.html', 'w', encoding='utf-8')
f.write(b.getPage())
f.close()
r += ' => '
for c in v.getConfs():
f = open(outputdir+'/'+c.getKey()+'.html', 'w', encoding='utf-8')
f.write(c.getPage())
f.close()
for p in c.papers:
f = open(outputdir+'/'+p.getKey()+'.html', 'w', encoding='utf-8')
f.write(p.getPage())
f.close()
purekey = c.getKey().replace(v.getKey(), '').replace('-', ' ').strip()
r += '{} [{}], '.format(purekey, C.yellow(len(c.papers)))
print(r)
# generate the icon lineup
icons = []
linked = []
pngs = [lastSlash(png).split('.')[0] for png in glob.glob(outputdir + '/stuff/*.png')]
pngs = [png for png in pngs \
if not (png.startswith('a-') or png.startswith('p-') or png.startswith('ico-')\
or png in ('cc-by', 'xhtml', 'css', 'open-knowledge', 'edit'))]
for brand in glob.glob(outputdir + '/*.brand.html'):
pure = lastSlash(brand).split('.')[0]
img = pure.lower().replace(' ', '')
if img in pngs:
pic = '<div class="wider"><a href="{0}.brand.html"><img class="abc" src="{1}" alt="{0}"/></a><span>{0}</span></div>'.format(\
pure,
'stuff/'+img+'.png')
pngs.remove(img)
icons.append(pic)
else:
# print('No image for', pure)
pass
corner = {'ada': 'TRI-Ada', 'comparch': 'CompArch', 'floc': 'FLoC', 'bibsleigh': 'index'}
for pure in pngs:
venueCandidate = corner[pure] if pure in corner else pure.upper()
canlink = sorted(glob.glob(outputdir + '/' + venueCandidate + '*.html'), key=len)
if canlink:
pic = '<div class="wider"><a href="{0}"><img class="abc" src="stuff/{1}.png" alt="{2}"/></a><span>{2}</span></div>'.format(\
canlink[0].split('/')[-1],
pure,
venueCandidate,
canlink[0].split('/')[0])
elif pure == 'twitter':
pic = '<div class="wider"><a href="https://about.twitter.com/company/brand-assets"><img class="abc" src="stuff/twitter.png" alt="Twitter"/></a><span>Twitter</span></div>'
elif pure == 'email':
pic = '<div class="wider"><a href="mailto:vadim@grammarware.net"><img class="abc" src="stuff/email.png" alt="e-mail"/></a><span>email</span></div>'
else:
print('Lonely', pure)
pic = '<img class="abc" src="stuff/{0}.png" alt="{0}"/>'.format(pure)
icons.append(pic)
# find last year of each venue
# for ven in glob.glob(corpusdir + '/*'):
# venname = lastSlash(ven)
# newstuff += '<strong><a href="http://dblp.uni-trier.de/db/conf/{}/">{} {}</a></strong>, '.format(venname.lower(), venname, nextYear(ven))
# print(lastSlash(ven), ':', lastYear(ven))
# write "more info" file
f = open(outputdir+'/about.html', 'w', encoding='utf-8')
f.write(aboutHTML.format(\
len(icons),
'<div class="minibar">' + '\n'.join(sorted(icons)) + '</div>'
))
f.close()
print('{}: {} venues, {} papers\n{}'.format(
C.purple('BibSLEIGH'),
C.red(len(sleigh.venues)),
C.red(sleigh.numOfPapers()),
C.purple('=' * 42)))
# generate the index
f = open(outputdir + '/index.html', 'w', encoding='utf-8')
f.write(sleigh.getPage())
f.close()
# generate all individual pages
# if False:
for v in sleigh.venues:
r = C.blue(v.getKey())
f = open(outputdir + '/' + v.getKey() + '.html', 'w', encoding='utf-8')
f.write(v.getPage())
f.close()
if v.brands:
r += '{' + '+'.join([C.blue(b.getKey()) for b in v.brands]) + '}'
for b in v.brands:
f = open(outputdir + '/' + b.getKey() + '.brand.html', 'w', encoding='utf-8')
f.write(b.getPage())
f.close()
r += ' => '
for c in v.getConfs():
f = open(outputdir + '/' + c.getKey() + '.html', 'w', encoding='utf-8')
f.write(c.getPage())
f.close()
for p in c.papers:
f = open(outputdir + '/' + p.getKey() + '.html', 'w', encoding='utf-8')
f.write(p.getPage())
f.close()
purekey = c.getKey().replace(v.getKey(), '').replace('-', ' ').strip()
r += '{} [{}], '.format(purekey, C.yellow(len(c.papers)))
print(r)
# generate the icon lineup
icons = []
linked = []
pngs = [lastSlash(png).split('.')[0] for png in glob.glob(outputdir + '/stuff/*.png')]
pngs = [png for png in pngs \
if not (png.startswith('a-') or png.startswith('p-') or png.startswith('ico-')
or png in ('cc-by', 'xhtml', 'css', 'open-knowledge', 'edit'))]
for brand in glob.glob(outputdir + '/*.brand.html'):
pure = lastSlash(brand).split('.')[0]
img = pure.lower().replace(' ', '')
if img in pngs:
pic = '<div class="wider"><a href="{0}.brand.html"><img class="abc" src="{1}" alt="{0}"/></a><span>{0}</span></div>'.format( \
pure,
'stuff/' + img + '.png')
pngs.remove(img)
icons.append(pic)
else:
# print('No image for', pure)
pass
corner = {'ada': 'TRI-Ada', 'comparch': 'CompArch', 'floc': 'FLoC', 'bibsleigh': 'index'}
for pure in pngs:
venueCandidate = corner[pure] if pure in corner else pure.upper()
canlink = sorted(glob.glob(outputdir + '/' + venueCandidate + '*.html'), key=len)
if canlink:
pic = '<div class="wider"><a href="{0}"><img class="abc" src="stuff/{1}.png" alt="{2}"/></a><span>{2}</span></div>'.format( \
canlink[0].split('/')[-1],
pure,
venueCandidate,
canlink[0].split('/')[0])
elif pure == 'twitter':
pic = '<div class="wider"><a href="https://about.twitter.com/company/brand-assets"><img class="abc" src="stuff/twitter.png" alt="Twitter"/></a><span>Twitter</span></div>'
elif pure == 'email':
pic = '<div class="wider"><a href="mailto:vadim@grammarware.net"><img class="abc" src="stuff/email.png" alt="e-mail"/></a><span>email</span></div>'
else:
print('Lonely', pure)
pic = '<img class="abc" src="stuff/{0}.png" alt="{0}"/>'.format(pure)
icons.append(pic)
# find last year of each venue
# for ven in glob.glob(corpusdir + '/*'):
# venname = lastSlash(ven)
# newstuff += '<strong><a href="http://dblp.uni-trier.de/db/conf/{}/">{} {}</a></strong>, '.format(venname.lower(), venname, nextYear(ven))
# print(lastSlash(ven), ':', lastYear(ven))
# write "more info" file
f = open(outputdir + '/about.html', 'w', encoding='utf-8')
f.write(aboutHTML.format(
len(icons),
'<div class="minibar">' + '\n'.join(sorted(icons)) + '</div>'
))
f.close()

# generate the DBLP sync page
cell_by_conf_by_year = {}
Ys = [2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009]
dblplinks = {}

# generate the DBLP sync page
cell_by_conf_by_year = {}
Ys = [2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010]
dblplinks = {}
with open(ienputdir + '/meta/dblpguide.sync', 'r') as f:
for line in f:
if not line or line.startswith('#'):
continue
words = line.split('|')
if len(words) != 3:
print('- Metaline {} skipped!'.format(words))
continue
name = words[0].strip()
dome = words[1].strip()
dblp = words[2].strip()
cell_by_conf_by_year[name] = {}
dblplinks[name] = dblp
for y in Ys:
cell_by_conf_by_year[name][y] = '(no)'
v = sleigh.getVenue(dome)
if v:
for yy in Ys:
y = v.getYear(yy)
if y:
ckey = '{}-{}'.format(name, yy)
c = y.getConf(ckey)
if c:
cell_by_conf_by_year[name][yy] = c.getIconItem2('', '')
else:
# print('- Conference {} of year {} in venue {} not found in the corpus'.format(ckey, yy, name))
for alt in 'v1', 'p1', 'c1', '1', 'J':
ckey = '{}-{}-{}'.format(name, alt, yy)
c = y.getConf(ckey)
if c:
cell_by_conf_by_year[name][yy] = c.getIconItem2('', '')
break
# else:
# print('- Year {} in venue {} not found in the corpus among {}'.format(yy, name, [z.year for z in v.years]))
# else:
# print('- Venue {} not found in the corpus'.format(name))

with open(ienputdir+'/meta/dblpguide.sync', 'r') as f:
for line in f:
if not line or line.startswith('#'):
continue
words = line.split('|')
if len(words) != 3:
print('- Metaline {} skipped!'.format(words))
continue
name = words[0].strip()
dome = words[1].strip()
dblp = words[2].strip()
cell_by_conf_by_year[name] = {}
dblplinks[name] = dblp
for y in Ys:
cell_by_conf_by_year[name][y] = '(no)'
v = sleigh.getVenue(dome)
if v:
for yy in Ys:
y = v.getYear(yy)
if y:
ckey = '{}-{}'.format(name, yy)
c = y.getConf(ckey)
if c:
cell_by_conf_by_year[name][yy] = c.getIconItem2('','')
else:
print('- Conference {} of year {} in venue {} not found in the corpus'.format(ckey, yy, name))
else:
print('- Year {} in venue {} not found in the corpus among {}'.format(yy, name, [z.year for z in v.years]))
else:
print('- Venue {} not found in the corpus'.format(name))
table = '<table>'
table += '<tr><td></td>'
for y in Ys:
table += '<th>{}</th>\n'.format(y)
table += '</tr>'
# print (cell_by_conf_by_year)
for name in sorted(cell_by_conf_by_year.keys()):
table += '<tr><th><a href="{}.brand.html">[@]</a> <a href="{}">{}</a></th>'.format(name, dblplinks[name], name)
for y in Ys:
table += '<td>{}</td>\n'.format(cell_by_conf_by_year[name][y])
table += '</tr>'
table += '</table>'

table = '<table>'
table += '<tr><td></td>'
for y in Ys:
table += '<th>{}</th>\n'.format(y)
table += '</tr>'
# print (cell_by_conf_by_year)
for name in sorted(cell_by_conf_by_year.keys()):
table += '<tr><th><a href="{}.brand.html">[@]</a> <a href="{}">{}</a></th>'.format(name, dblplinks[name],name)
for y in Ys:
table += '<td>{}</td>\n'.format(cell_by_conf_by_year[name][y])
table += '</tr>'
table += '</table>'
with open(outputdir + '/sync.html', 'w', encoding='utf-8') as f:
f.write(syncHTML.format(table))

with open(outputdir+'/sync.html', 'w', encoding='utf-8') as f:
f.write(syncHTML.format(table))
print('{}\nDone with {} venues, {} papers.'.format(
C.purple('=' * 42),
C.red(len(sleigh.venues)),
C.red(sleigh.numOfPapers())))

print('{}\nDone with {} venues, {} papers.'.format(\
C.purple('='*42),
C.red(len(sleigh.venues)),
C.red(sleigh.numOfPapers())))

if __name__ == "__main__":
main()
# cProfile.run('main()')
main()
# cProfile.run('main()')
Loading

0 comments on commit c4ee5dc

Please sign in to comment.