Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call in Python not command line #69

Open
stuchalk opened this issue Oct 4, 2022 · 5 comments
Open

Call in Python not command line #69

stuchalk opened this issue Oct 4, 2022 · 5 comments

Comments

@stuchalk
Copy link

stuchalk commented Oct 4, 2022

Can you add documentation how to call scraper in Python code rather than the command line? This would be very helpful for a new project I am working on that goes even further than this - which is awesome by the way...:)

@leebrian
Copy link
Collaborator

leebrian commented Oct 4, 2022

I don't know how useful or generally desired that is as the tool is intended to be called from the command line.

If you want to call it from another python program, you can look at the main method in the package and invoke the parts you would like to use,

@stuchalk
Copy link
Author

stuchalk commented Oct 4, 2022

Thanks for quick reply. Took a quick look at main and I will see what I can do. Would you consider a PR to add this functionality?

@leebrian
Copy link
Collaborator

leebrian commented Oct 4, 2022

Definitely, I think a PR that refactors this to be more program callable would be nice. It should be possible to refactor this and keep the command line functionality the same.

@stuchalk
Copy link
Author

stuchalk commented Oct 4, 2022

OK, I will fork the repo and work on it.

@IanLee1521
Copy link
Member

@stuchalk just to chime in with @leebrian -- yes, would definitely consider a PR that changes things around, but at a glance if you didn't want to do that, I think this is the meat you'd be looking for:

code_json = code_gov.process_config(config_json)
code_gov.force_attributes(code_json, config_json)
logger.info("Number of Projects: %s", len(code_json["releases"]))
output_filepath = args.output_filename
if output_path is not None:
output_filepath = os.path.join(output_path, output_filepath)
with open(output_filepath, "w", encoding="utf-8") as fp:
logger.info("Writing output to: %s", output_filepath)
fp.write(code_json.to_json())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants