Skip to content

Commit

Permalink
json output (#24)
Browse files Browse the repository at this point in the history
* checkpoint

* docs

* cleanup
  • Loading branch information
dogweather authored Dec 10, 2023
1 parent 9246be6 commit 98e171f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

## Retrieves legal citations and bibliograhic info from a web page

This is currently for internal use: It outputs Ruby code that creates
ActiveRecord objects. Next version will output JSON.
This is currently for internal use: It outputs JSON or Ruby code.


```bash
Expand All @@ -13,21 +12,17 @@ $ retrieve https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-

produces...

```ruby
Source.find_or_create_by!(name: "Probate Stars", url: "https://probatestars.com")

NewsImport.add(
Item.find_or_create_by(
url: URI('https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/').to_s,
title: "Texas Trust Protector Has No Fiduciary Duty to Settlor",
summary: "Under Texas law a trust protector has no fiduciary duty to the settlor of the trust, but may have one to the trustee or beneficiaires.",
secondary_source: Source.find_by!(name: 'Probate Stars'),
published_on: Date.parse('2020-05-19'),
),
[
'Tex. Prop. Code Section 114.0031'
]
)
```json
{
"title": "What Not to Say at a Drunk Driving Stop",
"citations": [
"Tex. Transp. Code Title 7 Subtitle J Chapter 724"
],
"description": "During a DUI or DWI stop in Orange, TX, it's crucial to navigate the situation wisely. Refrain from admissions of guilt, making incriminating statements, and oversharing personal details. Stay calm, avoid arguing, cooperate without compromising rights, and wisely choose when to mention legal counsel. Making the right choices during the stop can protect your interests. The Bearden Law Firm is here to help.",
"source_name": "The Bearden Law Firm",
"source_url": "https://beardenlawfirm.net",
"date_modified": "2023-10-30"
}
```


Expand Down
7 changes: 3 additions & 4 deletions lib/code_gen.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
alias News.Article

defmodule CodeGen do
@moduledoc """
A module for generating code.
Expand All @@ -6,10 +8,7 @@ defmodule CodeGen do

@spec ruby_code(binary) :: binary
def ruby_code(url) do
article =
url
|> URI.parse()
|> News.Article.parse()
article = Article.parse(url)

citation_list =
article.citations
Expand Down
5 changes: 5 additions & 0 deletions lib/news/article.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule News.Article do
:source_url,
:date_modified
]
@derive Jason.Encoder
defstruct [
:citations,
:title,
Expand All @@ -32,6 +33,10 @@ defmodule News.Article do
@doc """
Find citations in a string of HTML or from a URL.
"""
def parse(url) when is_binary(url) do
parse(URI.parse(url))
end

def parse(%URI{} = uri) do
url = URI.to_string(uri)
temp_file = News.File.tmp_file!(url)
Expand Down
4 changes: 4 additions & 0 deletions retrieve.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
#

IO.puts CodeGen.ruby_code(url)

# Output JSON
# IO.puts "\n\n"
# News.Article.parse(url) |> Jason.encode!(pretty: true) |> IO.puts()

0 comments on commit 98e171f

Please sign in to comment.