-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
base: main
Are you sure you want to change the base?
Conversation
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
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: cl/scrapers/tasks.py
Did you find this useful? React with a 👍 or 👎 |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
for cluster in qs: | ||
opinions = cluster.sub_opinions.all() | ||
for op in opinions: | ||
rerun_extract_from_text(op, juriscraper_module, stats) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
789ae66
to
2838202
Compare
- 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
2838202
to
6a1fadb
Compare
Helps solve: freelawproject/juriscraper#858