Skip to content

Commit

Permalink
Fix new bills not being added
Browse files Browse the repository at this point in the history
  • Loading branch information
limdingwen committed Aug 6, 2024
1 parent f0d12d1 commit 6c0d29e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions supabase/functions/lib/shared-functions/scrape-bills-introduced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(".");
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6c0d29e

Please sign in to comment.