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

feat(scrapers.update_from_text): new command #4520

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

grossir
Copy link
Contributor

@grossir grossir commented Oct 1, 2024

Helps solve: freelawproject/juriscraper#858

  • New command to re-run Site.extract_from_text over downloaded opinions
  • Able to filter by Docket.court_id , OpinionCluster.date_filed, OpinionCluster.precedential_status
  • Updates tasks.update_from_document_text to return information for logging purposes
  • Updates test_opinion_scraper to get a Site.extract_from_text method

Helps solve: freelawproject/juriscraper#858

- New command to re-run Site.extract_from_text over downloaded opinions
- Able to filter by Docket.court_id ,  OpinionCluster.date_filed, OpinionCluster.precedential_status
- Updates tasks.update_from_document_text to return information for logging purposes
- Updates test_opinion_scraper to get a Site.extract_from_text method
Copy link

sentry-io bot commented Oct 1, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: cl/scrapers/tasks.py

Function Unhandled Issue
update_document_from_text IndexError: list index out of range cl.scrapers.t...
Event Count: 2

Did you find this useful? React with a 👍 or 👎

@grossir grossir requested a review from flooie October 1, 2024 18:06
Comment on lines 127 to 163
stats = {"Docket": 0, "OpinionCluster": 0, "Opinion": 0, "Citation": 0}

if options["opinion_ids"]:
opinions = Opinion.objects.filter(id__in=options["opinion_ids"])
for op in opinions:
rerun_extract_from_text(op, juriscraper_module, stats)

logger.info("Modified objects counts: %s", stats)
return

if not (options["date_filed_gte"] and options["date_filed_lte"]):
raise ValueError(
"Both `date-filed-gte` and `date-filed-lte` arguments should have values"
)

court_id = juriscraper_module.split(".")[-1].split("_")[0]
gte_date = datetime.strptime(options["date_filed_gte"], "%Y/%m/%d")
lte_date = datetime.strptime(options["date_filed_lte"], "%Y/%m/%d")
query = {
"docket__court_id": court_id,
"date_filed__gte": gte_date,
"date_filed__lte": lte_date,
}

if options["cluster_status"]:
query["precedential_status"] = options["cluster_status"]

qs = OpinionCluster.objects.filter(**query).prefetch_related(
"sub_opinions"
)
for cluster in qs:
opinions = cluster.sub_opinions.all()
for op in opinions:
rerun_extract_from_text(op, juriscraper_module, stats)

logger.info("Modified objects counts: %s", stats)
self.stats = stats
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe its just me but I prefer to have a clean handle method that doesnt contain large portions of code to run and passes that off. do you think we could move this out of the handle into its own method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a Command's handle should have the code to manipulate the input arguments, otherwise it would be just boilerplate taking up space. I actually tried to abstract it out, and the handle would look like this, which I don't think is good:

def handle(self, *args, **options):
     super().handle(*args, **options)
     some_other_function(options)

Comment on lines 157 to 160
for cluster in qs:
opinions = cluster.sub_opinions.all()
for op in opinions:
rerun_extract_from_text(op, juriscraper_module, stats)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible to have opinions that are merged with Harvard. If thats the case this could bring back empty plain_text and html fields. which will crash

Copy link
Contributor

Choose a reason for hiding this comment

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

cl/scrapers/tasks.py Outdated Show resolved Hide resolved
@grossir grossir force-pushed the scrapers_update_from_text_command branch 3 times, most recently from 789ae66 to 2838202 Compare October 28, 2024 18:01
- validate citation objects from `Site.extract_from_text`. Add tests for this
- abstract --courts required argument for scrapers into ScraperCommand class
also, made it more flexible
- refactor cl_scrape_opinions; cl_scrape_oral_arguments to account for this
- delete cl.scrapers.utils.extract_recap_documents which was generating a
circular import. This function was not used anywhere
@grossir grossir force-pushed the scrapers_update_from_text_command branch from 2838202 to 6a1fadb Compare October 28, 2024 18:17
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

Successfully merging this pull request may close these issues.

2 participants