news_array = [{ keys[n]: value for n, value in enumerate(new) } for new in zip(news.header_scraper(), news.description_scraper(), news.link_scraper())] json_object = json.dumps(news_array, indent=4) filename = f"./json_files/{Helper.filename_generator(2)}" if os.path.exists(filename): os.remove(filename) with open(filename, 'x') as output_file: output_file.write(json_object) if __name__ == "__main__": name = UserOptions(input('¿Cual es tu nombre: ')) name.greeting() try: p_number = int( input('¿Cuantas noticias deseas investigar? (max. 50): ')) if p_number > 50 or p_number < 0: raise ValueError( 'Por favor inserte un número de página valido (valor entero)') output = int( input( '¿En que formato quieres recibir las noticias?\n1. CSV\n2. JSON\n\nEleccion: ' )) if output < 1 or output > 2: raise ValueError( 'Por favor inserte un número de opción valido (1 o 2)')
def main(): parser = argparse.ArgumentParser( prog="Craft", description= "Craft is an open source meta build system and package manager." "It manages dependencies and builds libraries and applications from source, on Windows, Mac, Linux and FreeBSD.", epilog="For more information visit https://community.kde.org/Craft.\n" "Send feedback to <*****@*****.**>.") parser.add_argument( "-p", "--probe", action="store_true", help= "probing: craft will only look which files it has to build according to the list of installed files and according to the dependencies of the package." ) parser.add_argument("--list-file", action="store", help="Build all packages from the ini file provided") parser.add_argument( "--options", action="append", default=CraftCore.settings.getList("General", "Options", ""), help= "Set craft property from string <OPTIONS>. An example for is extragear/kdevelop.version=5.3 or [Compile]MakeProgram=jom." ) parser.add_argument( "-q", "--stayquiet", action="store_true", dest="stayQuiet", help="quiet: there should be no output - The verbose level should be 0" ) parser.add_argument( "--create-cache", action="store_true", dest="createCache", default=CraftCore.settings.getboolean("Packager", "CreateCache", "False"), help="Create a binary cache, the setting is overwritten by --no-cache") parser.add_argument( "--use-cache", action="store_true", dest="useCache", default=CraftCore.settings.getboolean("Packager", "UseCache", "False"), help="Use a binary cache, the setting is overwritten by --no-cache") parser.add_argument("--no-cache", action="store_true", dest="noCache", default=False, help="Don't create or use the binary cache") parser.add_argument( "--destroy-craft-root", action="store_true", dest="doDestroyCraftRoot", default=False, help= "DANGEROUS: Recursively delete everything in the Craft root directory besides the CraftSettings.ini, the download directory and the craft folder itself" ) parser.add_argument( "--offline", action="store_true", default=CraftCore.settings.getboolean("General", "WorkOffline", False), help= "do not try to connect to the internet: KDE packages will try to use an existing source tree and other packages would try to use existing packages in the download directory.\ If that doesn't work, the build will fail.") parser.add_argument( "--buildtype", choices=["Release", "RelWithDebInfo", "MinSizeRel", "Debug"], dest="buildType", default=CraftCore.settings.get("Compile", "BuildType", "RelWithDebInfo"), help="This will override the build type set in your CraftSettings.ini." ) parser.add_argument( "-v", "--verbose", action="count", default=int(CraftCore.settings.get("CraftDebug", "Verbose", "0")), help= " verbose: increases the verbose level of craft. Default is 1. verbose level 1 contains some notes from craft, all output of cmake, make and other programs that are used.\ verbose level 2a dds an option VERBOSE=1 to make and craft is more verbose highest level is verbose level 3." ) parser.add_argument( "-i", "--ignoreInstalled", action="store_true", help= "ignore install: using this option will install a package over an existing install. This can be useful if you want to check some new code and your last build isn't that old." ) parser.add_argument( "--resolve-deps", action="store", help= "Similar to -i, all dependencies will be resolved and the action is applied on them" ) parser.add_argument( "--target", action="store", help="This will override the build of the default target.") parser.add_argument( "--search", action="store_true", help= "This will search for a package or a description matching or similar to the search term." ) parser.add_argument( "--src-dir", action="store", dest="srcDir", help="This will override the source dir and enable the offline mode") parser.add_argument("--ci-mode", action="store_true", default=CraftCore.settings.getboolean( "ContinuousIntegration", "Enabled", False), dest="ciMode", help="Enables the ci mode") parser.add_argument("--add-blueprint-repository", action="store", help="Installs a blueprint repository", metavar="URL") actionHandler = ActionHandler(parser) for x in sorted([ "fetch", "fetch-binary", "unpack", "configure", ("compile", { "help": "Same as --configure --make" }), "make", "install", "install-deps", "qmerge", "post-qmerge", "post-install", "package", "unmerge", "test", "createpatch", ("install-to-desktop", { "help": argparse.SUPPRESS }) ], key=lambda x: x[0] if isinstance(x, tuple) else x): if isinstance(x, tuple): actionHandler.addAction(x[0], **x[1]) else: actionHandler.addAction(x) actionHandler.addAction("update", help="Update all installed packages") # read-only actions actionHandler.addAction( "print-installed", help= "This will show a list of all packages that are installed currently.") actionHandler.addAction( "print-files", help="Print the files installed by the package and exit") actionHandler.addActionWithArg("search-file", help="Print packages owning the file") actionHandler.addActionWithArg("get", help="Get any value from a Blueprint") actionHandler.addActionWithArg( "set", help="Permanently set a config value of a Blueprint") actionHandler.addActionWithArg( "run", nargs=argparse.REMAINDER, help="Run an application in the Craft environment") actionHandler.addActionWithArg( "run-detached", nargs=argparse.REMAINDER, help="Run an application in the Craft environment and detach") actionHandler.addAction("clean-unused", help="Clean unused files of all packages") # other actions parser.add_argument( "--version", action="version", version=f"%(prog)s {CraftSetupHelper.SetupHelper.CraftVersion}") parser.add_argument("packageNames", nargs=argparse.REMAINDER) args = parser.parse_args() if args.stayQuiet: CraftCore.debug.setVerbose(-1) elif args.verbose: CraftCore.debug.setVerbose(args.verbose) CraftCore.settings.set("General", "WorkOffline", args.offline or args.srcDir is not None) CraftCore.settings.set("Compile", "BuildType", args.buildType) CraftCore.settings.set("General", "Options", ";".join(args.options)) CraftCore.settings.set("Packager", "CreateCache", not args.noCache and args.createCache) CraftCore.settings.set("Packager", "UseCache", not args.noCache and args.useCache) CraftCore.settings.set("ContinuousIntegration", "SourceDir", args.srcDir) CraftCore.settings.set("ContinuousIntegration", "Enabled", args.ciMode) CraftSetupHelper.SetupHelper.printBanner() if args.doDestroyCraftRoot: return CraftCommands.destroyCraftRoot() # macOS: Depending how you started / forwarded your command, macOS would append # a process identifier to the craft arguments in the form of a -psnXXX parameter. # This parameter is a process identifier and rely to the craft command, not to the # command to run by craft, let remove it. if args.run: run = list(filter(lambda entry: not entry.startswith("-psn"), args.run)) useShell = True if CraftCore.compiler.isMacOS: useShell = not '.app' in run[1] if run[0].endswith( "open") else not '.app' in run[0] return utils.system(run, shell=useShell) elif args.run_detached: run_detached = list( filter(lambda entry: not entry.startswith("-psn"), args.run_detached)) kwargs = {} if CraftCore.compiler.isWindows: kwargs["creationflags"] = subprocess.DETACHED_PROCESS return subprocess.Popen(run_detached, **kwargs) if args.add_blueprint_repository: return CraftCommands.addBlueprintsRepository( args.add_blueprint_repository, args) if CraftCore.settings.getboolean("Packager", "CreateCache"): # we are in cache creation mode, ensure to create a 7z image and not an installer CraftCore.settings.set("Packager", "PackageType", "SevenZipPackager") UserOptions.setOptions(args.options) if args.search: for package in args.packageNames: blueprintSearch.printSearch(package) return True for action in actionHandler.parseFinalAction(args, "all"): tempArgs = copy.deepcopy(args) if action in ["install-deps", "package"]: tempArgs.ignoreInstalled = True CraftCore.log.debug("buildAction: %s" % action) CraftCore.log.debug("doPretend: %s" % tempArgs.probe) CraftCore.log.debug("packageName: %s" % tempArgs.packageNames) CraftCore.log.debug("buildType: %s" % tempArgs.buildType) CraftCore.log.debug("verbose: %d" % CraftCore.debug.verbose()) CraftCore.log.debug("Craft: %s" % CraftCore.standardDirs.craftRoot()) packageNames = tempArgs.packageNames if tempArgs.list_file: if not os.path.exists(tempArgs.list_file): CraftCore.log.error( f"List file {tempArgs.list_file!r} does not exist") return False if not packageNames: packageNames = [] packageNames += CraftCommands.readListFile(tempArgs.list_file) if action == "print-installed": InstallDB.printInstalled() elif action == "search-file": InstallDB.printPackagesForFileSearch(tempArgs.search_file) elif action == "set": CraftCommands.setOption(packageNames, args.set) elif action == "clean-unused": CraftCommands.cleanBuildFiles(cleanArchives=True, cleanImages=True, cleanInstalledImages=False, cleanBuildDir=True, packages=blueprintSearch.packages()) elif action == "update": return CraftCommands.updateInstalled(tempArgs) else: if not packageNames: return True package = CraftCommands.resolvePackage(packageNames, version=tempArgs.target) if not CraftCommands.run(package, action, tempArgs): return False return True
def main(): parser = argparse.ArgumentParser( prog="Craft", description= "Craft is an open source meta build system and package manager." "It manages dependencies and builds libraries and applications from source, on Windows, Mac, Linux and FreeBSD.", epilog="For more information visit https://community.kde.org/Craft.\n" "Send feedback to <*****@*****.**>.") parser.add_argument( "-p", "--probe", action="store_true", help= "probing: craft will only look which files it has to build according to the list of installed files and according to the dependencies of the package." ) parser.add_argument("--list-file", action="store", help="Build all packages from the ini file provided") parser.add_argument( "--options", action="append", default=CraftCore.settings.getList("General", "Options", ""), help= "Set craft property from string <OPTIONS>. An example for is \"cmake.openIDE=1\" see options.py for more informations." ) parser.add_argument( "-q", "--stayquiet", action="store_true", dest="stayQuiet", help="quiet: there should be no output - The verbose level should be 0" ) parser.add_argument( "--create-cache", action="store_true", dest="createCache", default=CraftCore.settings.getboolean("Packager", "CreateCache", "False"), help="Create a binary cache, the setting is overwritten by --no-cache") parser.add_argument( "--use-cache", action="store_true", dest="useCache", default=CraftCore.settings.getboolean("Packager", "UseCache", "False"), help="Use a binary cache, the setting is overwritten by --no-cache") parser.add_argument("--no-cache", action="store_true", dest="noCache", default=False, help="Don't create or use the binary cache") parser.add_argument( "--destroy-craft-root", action="store_true", dest="doDestroyCraftRoot", default=False, help= "DANGEROUS: Recursively delete everything in the Craft root directory besides the CraftSettings.ini, the download directory and the craft folder itself" ) parser.add_argument( "--offline", action="store_true", default=CraftCore.settings.getboolean("General", "WorkOffline", False), help= "do not try to connect to the internet: KDE packages will try to use an existing source tree and other packages would try to use existing packages in the download directory.\ If that doesn't work, the build will fail.") parser.add_argument( "--buildtype", choices=["Release", "RelWithDebInfo", "MinSizeRel", "Debug"], dest="buildType", default=CraftCore.settings.get("Compile", "BuildType", "RelWithDebInfo"), help="This will override the build type set in your CraftSettings.ini." ) parser.add_argument( "-v", "--verbose", action="count", default=int(CraftCore.settings.get("CraftDebug", "Verbose", "0")), help= " verbose: increases the verbose level of craft. Default is 1. verbose level 1 contains some notes from craft, all output of cmake, make and other programs that are used.\ verbose level 2a dds an option VERBOSE=1 to make and craft is more verbose highest level is verbose level 3." ) parser.add_argument( "-i", "--ignoreInstalled", action="store_true", help= "ignore install: using this option will install a package over an existing install. This can be useful if you want to check some new code and your last build isn't that old." ) parser.add_argument( "--target", action="store", help="This will override the build of the default target.") parser.add_argument( "--search", action="store_true", help= "This will search for a package or a description matching or similar to the search term." ) parser.add_argument( "--log-dir", action="store", default=CraftCore.settings.get("CraftDebug", "LogDir", os.path.expanduser("~/.craft/")), help= "This will log the build output to a logfile in LOG_DIR for each package. Logging information is appended to existing logs." ) parser.add_argument( "--src-dir", action="store", dest="srcDir", help="This will override the source dir and enable the offline mode") parser.add_argument("--ci-mode", action="store_true", default=CraftCore.settings.getboolean( "ContinuousIntegration", "Enabled", False), dest="ciMode", help="Enables the ci mode") parser.add_argument("--add-blueprint-repository", action="store", help="Installs a blueprint repository", metavar="URL") actionHandler = ActionHandler(parser) for x in sorted([ "fetch", "fetch-binary", "unpack", "configure", ("compile", { "help": "Same as --configure --make" }), "make", "install", "install-deps", "qmerge", "post-install", "package", "unmerge", "test", "createpatch" ], key=lambda x: x[0] if isinstance(x, tuple) else x): if isinstance(x, tuple): actionHandler.addAction(x[0], **x[1]) else: actionHandler.addAction(x) # read-only actions actionHandler.addAction( "print-installed", help= "This will show a list of all packages that are installed currently.") actionHandler.addAction( "print-files", help="Print the files installed by the package and exit") actionHandler.addActionWithArg("search-file", help="Print packages owning the file") actionHandler.addActionWithArg("get", help="Get any value from a Blueprint") actionHandler.addActionWithArg( "set", help="Permanently set a config value of a Blueprint") actionHandler.addActionWithArg( "run", nargs="+", help="Run an application in the Craft environment") # other actions parser.add_argument( "--version", action="version", version=f"%(prog)s {CraftSetupHelper.SetupHelper.CraftVersion}") parser.add_argument("packageNames", nargs=argparse.REMAINDER) args = parser.parse_args() if args.doDestroyCraftRoot: return CraftCommands.destroyCraftRoot() if args.stayQuiet: CraftCore.debug.setVerbose(-1) elif args.verbose: CraftCore.debug.setVerbose(args.verbose) CraftCore.settings.set("General", "WorkOffline", args.offline or args.srcDir is not None) CraftCore.settings.set("Compile", "BuildType", args.buildType) CraftCore.settings.set("General", "Options", ";".join(args.options)) CraftCore.settings.set("CraftDebug", "LogDir", args.log_dir) CraftCore.settings.set("Packager", "CreateCache", not args.noCache and args.createCache) CraftCore.settings.set("Packager", "UseCache", not args.noCache and args.useCache) CraftCore.settings.set("ContinuousIntegration", "SourceDir", args.srcDir) CraftCore.settings.set("ContinuousIntegration", "Enabled", args.ciMode) helper = CraftSetupHelper.SetupHelper() if not "KDEROOT" in os.environ: helper.subst() helper.setupEnvironment() helper.printBanner() if args.run: return utils.system(args.run) if args.add_blueprint_repository: return CraftCommands.addBlueprintsRepository( args.add_blueprint_repository, args) if CraftCore.settings.getboolean("Packager", "CreateCache"): # we are in cache creation mode, ensure to create a 7z image and not an installer CraftCore.settings.set("Packager", "PackageType", "SevenZipPackager") UserOptions.setOptions(args.options) if args.search: for package in args.packageNames: blueprintSearch.printSearch(package) return True for action in actionHandler.parseFinalAction(args, "all"): tempArgs = copy.deepcopy(args) if action in ["install-deps", "package"]: tempArgs.ignoreInstalled = True CraftCore.log.debug("buildAction: %s" % action) CraftCore.log.debug("doPretend: %s" % tempArgs.probe) CraftCore.log.debug("packageName: %s" % tempArgs.packageNames) CraftCore.log.debug("buildType: %s" % tempArgs.buildType) CraftCore.log.debug("verbose: %d" % CraftCore.debug.verbose()) CraftCore.log.debug("Craft: %s" % CraftCore.standardDirs.craftRoot()) packageNames = tempArgs.packageNames if tempArgs.list_file: if not packageNames: packageNames = [] packageNames += CraftCommands.readListFile(tempArgs.list_file) if action == "print-installed": InstallDB.printInstalled() elif action == "search-file": InstallDB.printPackagesForFileSearch(tempArgs.search_file) elif action == "set": CraftCommands.setOption(packageNames, args.set) else: if not packageNames: return True package = CraftCommands.resolvePackage(packageNames, version=tempArgs.target) if not CraftCommands.run(package, action, tempArgs): return False return True