-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v1.0.3
- Loading branch information
Showing
1 changed file
with
17 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
Element, | ||
} from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"; | ||
import buildResponseProxy from "../utils/build-response-proxy.ts"; | ||
import { SupabaseClient } from "https://esm.sh/v135/@supabase/[email protected]/dist/module/index.d.ts"; | ||
|
||
function toIsoDate(dateString: string): string { | ||
const [day, month, year] = dateString.split("."); | ||
|
@@ -16,6 +17,21 @@ function sanitiseUrl(url: string) { | |
} | ||
|
||
// Scrapes recent bills metadata | ||
async function checkIfBillExists( | ||
supabase: SupabaseClient, | ||
scrapedData: { | ||
bill_no: string; | ||
}, | ||
) { | ||
const { data, error } = await supabase | ||
.from("bill") | ||
.select("bill_no") | ||
.eq("bill_no", scrapedData.bill_no) | ||
.maybeSingle(); | ||
if (error) throw error; | ||
return data != null; | ||
} | ||
|
||
// Does not scrape the actual bill text and does not actually summarise them | ||
export default async function scrapeBillsIntroduced(req: Request) { | ||
const supabase = createSupabase(); | ||
|
@@ -87,12 +103,7 @@ export default async function scrapeBillsIntroduced(req: Request) { | |
summary: null, | ||
}; | ||
|
||
const billExists = | ||
(await supabase | ||
.from("bill") | ||
.select("bill_no") | ||
.eq("bill_no", scrapedData.bill_no) | ||
.maybeSingle()) != null; | ||
const billExists = await checkIfBillExists(supabase, scrapedData); | ||
|
||
if (billExists) { | ||
// Make sure that we don't overwrite the original_text and summary values | ||
|