def main(): multiparser = MultiParser() config = multiparser.config story_providers = construct_story_providers_from_config_dict(config) title = config["title"] if "title" in config else None subtitle = config["subtitle"] if "subtitle" in config else None filename = multiparser.argumentOrConfig( "output", default= f"Goosepaper-{datetime.datetime.now().strftime('%Y-%B-%d-%H-%M')}.pdf") replace = multiparser.argumentOrConfig("replace", False) paper = Goosepaper(story_providers=story_providers, title=title, subtitle=subtitle) if filename.endswith(".html"): with open(filename, "w") as fh: fh.write(paper.to_html()) elif filename.endswith(".pdf"): paper.to_pdf(filename) elif filename.endswith(".epub"): paper.to_epub(filename) else: raise ValueError( f"Unknown file extension '{filename.split('.')[-1]}'.") if multiparser.argumentOrConfig("upload"): upload(filename, replace) return 0
def main(): parser = argparse.ArgumentParser( "Goosepaper generates and delivers a daily newspaper in PDF format.") parser.add_argument( "-c", "--config", required=False, default=None, help="The json file to use to generate this paper.", ) parser.add_argument( "-o", "--output", required=False, default= f"Goosepaper-{datetime.datetime.now().strftime('%Y-%B-%d-%H-%M')}.pdf", help="The output file path at which to save the paper", ) parser.add_argument( "-u", "--upload", action="store_true", required=False, help="Whether to upload the file to your remarkable using rmapy.", ) args = parser.parse_args() try: config = load_config_file(args.config) except FileNotFoundError as e: raise FileNotFoundError( f"Could not find the configuration file at {args.config}") from e story_providers = construct_story_providers_from_config_dict(config) paper = Goosepaper(story_providers=story_providers) if args.output.endswith(".html"): with open(args.output, "w") as fh: fh.write(paper.to_html()) elif args.output.endswith(".pdf"): paper.to_pdf(args.output) elif args.output.endswith(".epub"): paper.to_epub(args.output) else: raise ValueError( f"Unknown file extension '{args.output.split('.')[-1]}'.") if args.upload: upload(args.output) return 0
def main(): multiparser = MultiParser() config = multiparser.config nostory = multiparser.argumentOrConfig("nostory") filename = multiparser.argumentOrConfig( "output", default=f"Goosepaper-{datetime.datetime.now().strftime('%Y-%B-%d-%H-%M')}.pdf", ) if not nostory: # global nostory flag story_providers = construct_story_providers_from_config_dict(config) font_size = multiparser.argumentOrConfig("font_size", 14) title = config["title"] if "title" in config else None subtitle = config["subtitle"] if "subtitle" in config else None paper = Goosepaper( story_providers=story_providers, title=title, subtitle=subtitle ) if filename.endswith(".html"): with open(filename, "w") as fh: fh.write(paper.to_html()) elif filename.endswith(".pdf"): paper.to_pdf(filename, font_size=font_size) elif filename.endswith(".epub"): paper.to_epub(filename, font_size=font_size) else: print(f"Unknown file extension '{filename.split('.')[-1]}'.") exit(1) if multiparser.argumentOrConfig("upload"): if multiparser.argumentOrConfig("noupload"): print( "Honk! The 'upload' directive was found, but '--noupload' was also specified on the command line. Your goosepaper {0} was generated but I'm not uploading it.".format( filename ) ) else: do_upload(filepath=filename, multiparser=multiparser) return 0