<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import sys <EOL> from StringIO import StringIO <EOL> from time import localtime <EOL> import ads <EOL> import requests <EOL> from PyPDF2 import ( PdfFileReader , PdfFileWriter ) <EOL> def get_pdf ( article , debug = False ) : <EOL> """<STR_LIT>""" <EOL> print ( '<STR_LIT>' . format ( article ) ) <EOL> identifier = [ _ for _ in article . identifier if '<STR_LIT>' in _ ] <EOL> if identifier : <EOL> url = '<STR_LIT>' . format ( identifier [ <NUM_LIT:0> ] [ <NUM_LIT:9> : <NUM_LIT> ] , <EOL> '<STR_LIT>' . join ( _ for _ in identifier [ <NUM_LIT:0> ] [ <NUM_LIT> : ] if _ . isdigit ( ) ) ) <EOL> else : <EOL> params = { <EOL> '<STR_LIT>' : article . bibcode , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> url = requests . get ( '<STR_LIT>' , <EOL> params = params ) . url <EOL> q = requests . get ( url ) <EOL> if not q . ok : <EOL> print ( '<STR_LIT>' . format ( <EOL> article , q . status_code , url ) ) <EOL> if debug : q . raise_for_status ( ) <EOL> else : return None <EOL> if q . content . endswith ( '<STR_LIT>' ) : <EOL> print ( '<STR_LIT>' . format ( <EOL> article , url ) ) <EOL> return None <EOL> return q . content <EOL> def summarise_pdfs ( pdfs ) : <EOL> """<STR_LIT>""" <EOL> print ( '<STR_LIT>' . format ( <EOL> len ( pdfs ) , pdfs . count ( None ) ) ) <EOL> pdfs = [ _ for _ in pdfs if _ is not None ] <EOL> summary = PdfFileWriter ( ) <EOL> for pdf in pdfs : <EOL> summary . addPage ( PdfFileReader ( StringIO ( pdf ) ) . getPage ( <NUM_LIT:0> ) ) <EOL> return summary <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) >= <NUM_LIT:3> : <EOL> year , month = map ( int , ( sys . argv [ <NUM_LIT:1> : <NUM_LIT:3> ] ) ) <EOL> else : <EOL> now = localtime ( ) <EOL> year , month = ( now . tm_year , now . tm_mon - <NUM_LIT:1> ) <EOL> if <NUM_LIT:1> > month : year , month = ( year - <NUM_LIT:1> , month ) <EOL> print ( '<STR_LIT>' . format ( year , month ) ) <EOL> articles = ads . SearchQuery ( <EOL> q = '<STR_LIT>' '<STR_LIT>' . format ( year , month ) , <EOL> fl = [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> sort = '<STR_LIT>' ) <EOL> pdfs = map ( get_pdf , articles ) <EOL> with open ( '<STR_LIT>' . format ( year , month ) , '<STR_LIT:wb>' ) as fp : <EOL> summarise_pdfs ( pdfs ) . write ( fp ) </s>
