xdufacool/organize_bib.py
def gen_attachments(args):
    """Generate attachments for uploading to NSFC website."""
    bash_header = '#!/usr/bin/env bash'
    gs_options = ' '.join(['-dNOPAUSE', '-dBATCH',
                           '-sDEVICE=pdfwrite', '-dCompatibilityLevel=1.5',
                           '-dPDFSETTINGS=/ebook'])
    shrink_pdf = ['# Ref: https://www.techwalla.com/articles/reduce-pdf-file-size-linux', '\n',
                  'shrink_pdf()', '\n{\n',
                  f'  OPTIONS="{gs_options}"', '\n',
                  '  echo "Shrinking $1..."', '\n',
                  '  gs $OPTIONS -sOutputFile=$FOLDER/$1 $1', '\n',
                  '}\n\n']
    bash_lines = [bash_header, '\n\n',
                  'FOLDER="attachments"', '\n\n',
                  '[[ -d $FOLDER ]] || mkdir $FOLDER', '\n\n']
    bash_lines += shrink_pdf
    convertion_lines = []
    input_specs, output_specs = [], []
    with open(args.metadata, 'r') as stream:
        metadata = yaml.load(stream, Loader=Loader)
        for item in metadata:
            filename = item.get('file')
            if item.get('label', None) == 'masterpiece':
                # line = f'pdf2ps {filename} - | ps2pdf - $FOLDER/{filename}\n'
                line = f'shrink_pdf {filename}\n'
                convertion_lines.append(line)
            else:
                att_symbol = chr(ord('A') + len(input_specs))
                pages = item.get('ackpage', [])
                input_specs.append(f'      {att_symbol}={filename} \\\n')
                output_specs += [f'{att_symbol}{page}' for page in pages]

    # print(output_specs)
    if input_specs:
        input_specs[0] = 'pdftk ' + input_specs[0].strip() + '\n'
        output_lines = ['      cat ', ' '.join(output_specs),
                        ' output attachments.pdf', '\n\n',
                        'shrink_pdf attachments.pdf\n']
    else:
        output_lines = []
    # 'pdf2ps $FOLDER/attach-large.pdf - | ps2pdf - $FOLDER/attachments.pdf\n']
    with open(args.script, 'w') as scriptfile:
        scriptfile.writelines(bash_lines)
        scriptfile.writelines(convertion_lines)
        scriptfile.writelines(input_specs)
        scriptfile.writelines(output_lines)
Generate attachments for uploading to NSFC website.
Generate attachments for uploading to NSFC website.
Generate attachments for uploading to NSFC website .
def gen_attachments(args):
    bash_header = '#!/usr/bin/env bash'
    gs_options = ' '.join(['-dNOPAUSE', '-dBATCH',
                           '-sDEVICE=pdfwrite', '-dCompatibilityLevel=1.5',
                           '-dPDFSETTINGS=/ebook'])
    shrink_pdf = ['# Ref: https://www.techwalla.com/articles/reduce-pdf-file-size-linux', '\n',
                  'shrink_pdf()', '\n{\n',
                  f'  OPTIONS="{gs_options}"', '\n',
                  '  echo "Shrinking $1..."', '\n',
                  '  gs $OPTIONS -sOutputFile=$FOLDER/$1 $1', '\n',
                  '}\n\n']
    bash_lines = [bash_header, '\n\n',
                  'FOLDER="attachments"', '\n\n',
                  '[[ -d $FOLDER ]] || mkdir $FOLDER', '\n\n']
    bash_lines += shrink_pdf
    convertion_lines = []
    input_specs, output_specs = [], []
    with open(args.metadata, 'r') as stream:
        metadata = yaml.load(stream, Loader=Loader)
        for item in metadata:
            filename = item.get('file')
            if item.get('label', None) == 'masterpiece':
                line = f'shrink_pdf {filename}\n'
                convertion_lines.append(line)
            else:
                att_symbol = chr(ord('A') + len(input_specs))
                pages = item.get('ackpage', [])
                input_specs.append(f'      {att_symbol}={filename} \\\n')
                output_specs += [f'{att_symbol}{page}' for page in pages]
    if input_specs:
        input_specs[0] = 'pdftk ' + input_specs[0].strip() + '\n'
        output_lines = ['      cat ', ' '.join(output_specs),
                        ' output attachments.pdf', '\n\n',
                        'shrink_pdf attachments.pdf\n']
    else:
        output_lines = []
    with open(args.script, 'w') as scriptfile:
        scriptfile.writelines(bash_lines)
        scriptfile.writelines(convertion_lines)
        scriptfile.writelines(input_specs)
        scriptfile.writelines(output_lines)
def gen_attachments ( args ) : bash_header = '#!/usr/bin/env bash' gs_options = ' ' . join ( [ '-dNOPAUSE' , '-dBATCH' , '-sDEVICE=pdfwrite' , '-dCompatibilityLevel=1.5' , '-dPDFSETTINGS=/ebook' ] ) shrink_pdf = [ '# Ref: https://www.techwalla.com/articles/reduce-pdf-file-size-linux' , '\n' , 'shrink_pdf()' , '\n{\n' , f'  OPTIONS="{gs_options}"' , '\n' , '  echo "Shrinking $1..."' , '\n' , '  gs $OPTIONS -sOutputFile=$FOLDER/$1 $1' , '\n' , '}\n\n' ] bash_lines = [ bash_header , '\n\n' , 'FOLDER="attachments"' , '\n\n' , '[[ -d $FOLDER ]] || mkdir $FOLDER' , '\n\n' ] bash_lines += shrink_pdf convertion_lines = [ ] input_specs , output_specs = [ ] , [ ] with open ( args . metadata , 'r' ) as stream : metadata = yaml . load ( stream , Loader = Loader ) for item in metadata : filename = item . get ( 'file' ) if item . get ( 'label' , None ) == 'masterpiece' : line = f'shrink_pdf {filename}\n' convertion_lines . append ( line ) else : att_symbol = chr ( ord ( 'A' ) + len ( input_specs ) ) pages = item . get ( 'ackpage' , [ ] ) input_specs . append ( f'      {att_symbol}={filename} \\\n' ) output_specs += [ f'{att_symbol}{page}' for page in pages ] if input_specs : input_specs [ 0 ] = 'pdftk ' + input_specs [ 0 ] . strip ( ) + '\n' output_lines = [ '      cat ' , ' ' . join ( output_specs ) , ' output attachments.pdf' , '\n\n' , 'shrink_pdf attachments.pdf\n' ] else : output_lines = [ ] with open ( args . script , 'w' ) as scriptfile : scriptfile . writelines ( bash_lines ) scriptfile . writelines ( convertion_lines ) scriptfile . writelines ( input_specs ) scriptfile . writelines ( output_lines )
Generate attachments for uploading to NSFC website.
Generate attachments for uploading to NSFC website .
"""Generate attachments for uploading to NSFC website.""" # line = f'pdf2ps {filename} - | ps2pdf - $FOLDER/{filename}\n' # print(output_specs) # 'pdf2ps $FOLDER/attach-large.pdf - | ps2pdf - $FOLDER/attachments.pdf\n']
args