diff options
Diffstat (limited to 'util.py')
| -rw-r--r-- | util.py | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -87,6 +87,9 @@ def write_report(fn, title=None, keys=None, rows=[]): f.write("</html>") print("{} {}".format(fn, count)) +def percent(m, n): + return round(n / m * 100) + class NameLine(object): def __init__(self, s): self.s = s.strip() @@ -102,9 +105,12 @@ class BoldLine(object): class LinkLine(object): def __init__(self, href, txt): self.href = href - self.txt = txt.strip + self.txt = txt.strip() def __str__(self): - return '<a href="{}">{}</a>'.format(self.href, self.txt) + if self.href: + return '<a href="{}">{}</a>'.format(self.href, self.txt) + else: + return '<span class="gray">{}</a>'.format(self.txt) def write_table(f, keys, rows): count = 0 @@ -145,6 +151,13 @@ class DbPaper(object): @property def authors(self): return [ (author['ids'][0] if len(author['ids']) else '', author['name']) for author in self.data['authors'] ] + @property + def pdf_link(self): + if self.data['s2PdfUrl']: + return self.data['s2PdfUrl'] + if len(self.data['pdfUrls']): + return self.data['pdfUrls'][0] + return None def record(self): return [ self.paper_id, self.title, self.journal, self.year ] @@ -173,6 +186,9 @@ class RawPaper(object): @property def authors(self): return [ (author[0]['ids'][0] if len(author[0]['ids']) else '', author[0]['name']) for author in self.data['authors'] ] + @property + def pdf_link(self): + return self.data['primaryPaperLink'] or None def record(self): return [ self.paper_id, self.title, self.journal, self.year ] |
