diff options
Diffstat (limited to 'src/catalogue/catalogue.lil')
-rw-r--r-- | src/catalogue/catalogue.lil | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/catalogue/catalogue.lil b/src/catalogue/catalogue.lil new file mode 100644 index 0000000..0b68c02 --- /dev/null +++ b/src/catalogue/catalogue.lil @@ -0,0 +1,44 @@ +csv_db:"test.csv" + +on load_db db do + data:read[db] + out:readcsv[data "sss"] +end + +on save_db t db do + out:writecsv[t] + write[db out] +end + +on entry d t do + # where d is a table representing a new row to be added to t, an existing table + date_fmt_string:"date +%Y-%m-%d | tr -d '\n'" + wget_fmt_string:"wget -qO- " , d.url , " | grep -o \"<title>[^<]*\" | sed -e 's/<[^>]*>//g' | tr -d '\n'" + wget_res:shell[wget_fmt_string] + if wget_res.exit = -1 do + exit["\n wget failed\n"] # this is weaksauce, but better than nothing, I suppose + else + t:insert title:(wget_res.out) reference:(d.url) created_date:(shell[date_fmt_string].out) into t + end +end + +if args[2] do + # read in a csv, and store in memory as a table + catalogue:load_db[csv_db] + + if args[2] ~ "-l" do + show[catalogue] # listing everything is probs not the most ideal if you've got thousands of entries... + else + url:args[2] + + # add a row to the table stored in memory + row.url:url + row:table row + catalogue:entry[row catalogue] + + # write the updated data to csv + save_db[catalogue csv_db] + end +else + print["\n please pass a url as an argument\n"] +end \ No newline at end of file |