view bin/plinks.py @ 18:046dbe557911

write to tmp file implemented
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 07 Aug 2022 13:58:33 +0100
parents 04464ee31d66
children 38bab758e469
line wrap: on
line source

#!/usr/bin/env python3
import sys,pdfx,traceback
from datetime import datetime

def run(file):
  global pdf
  pdf=pdfx.PDFx(file)
  return pdf.get_references_as_dict()

f=sys.argv[1]

try:
  links=run(f)
  if bool(links) and (links.get('scrape',False) or
                      links.get('annot',False)):
    for k in links.keys():
      for l in links[k]:
        print("%s\t%s"%(k,l))
except Exception as e:
  if str(e)=='Unexpected EOF':
    print("%s:\t%s"%(datetime.now().isoformat(),e),file=sys.stderr)
  else:
    print("%s: "%(datetime.now().isoformat()),end='',file=sys.stderr)
    traceback.print_exc(file=sys.stderr)