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

Addition of Python function call 'scrape' #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ venv/
*.pyc
llnl_scraper.egg-info/
.vscode/
.idea/
scraper/unf.json
34 changes: 34 additions & 0 deletions scraper/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
""" functions to use the code as a project package """
from scraper import code_gov
import logging
import json

logger = logging.getLogger(__name__)


def scrape(configfile):
"""
run the scraper using the config.json file

Parameters
__________
configfile : path
file path to the configuration file with format as outlined in README.md

Returns
_______
json
a JSON file of the scraped metadata
"""

# open the config file
f = open(configfile)
config_json = json.load(f)
Comment on lines +25 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f = open(configfile)
config_json = json.load(f)
with open(configfile) as fp:
config_json = json.load(fp)


# process
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"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this logger call should move in to code_gov.process_config(...) so that the message happens at the time the objects are parsed? Thoughts?


# return
return code_json.to_json()