From f68dcda1938bd389dc03fb717420b27ec4c64db3 Mon Sep 17 00:00:00 2001 From: "Christopher P. Brown" Date: Fri, 24 Dec 2021 15:21:08 -0700 Subject: [PATCH] intitial commit --- csv2recutil.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ justfile | 15 ++++++++ sample.csv | 23 ++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 csv2recutil.md create mode 100644 justfile create mode 100644 sample.csv diff --git a/csv2recutil.md b/csv2recutil.md new file mode 100644 index 0000000..857a010 --- /dev/null +++ b/csv2recutil.md @@ -0,0 +1,94 @@ +# csv2recutil + +This script takes the path of a CSV file as an argument, and prints the data to stdout in [recutils] format + +[recutils]: https://www.gnu.org/software/recutils/manual/recutils.html + +## Usage + +`retro csv2recutil.md file.csv` + +Print message if no argument is given: + +~~~ +script:arguments #0 eq? [ 'Usage:_csv2recutil_ s:put nl nl ] if; +~~~ + +## File reader + +open file, get handle and size + +~~~ +'handle var 'size var +#0 script:get-argument file:open-for-reading !handle !size +~~~ + +readline utility + +~~~ +:get-line @handle file:read-line ; +~~~ + +## CSV to array + +declare `s:to-array/csv` function. Takes a string, returns an array. + +~~~ +:s:to-array/csv (s-a) +~~~ + +strip all the double quotes. NOTE: this will also strip all quotes in the body text. Might be better to chomp, reverse, chomp, reverse? + +~~~ +[ $" -eq? ] s:filter +~~~ + +Finally split on commas + +~~~ +$, s:tokenize +~~~ + +There, now you have an array + +(end function:) + +~~~ +; +~~~ + +## Main + +Get the headers: + +~~~ +get-line s:to-array/csv 'Headers var-n +~~~ + +declare a var for the current line so we can assign to it + +~~~ +'Current var +~~~ + +Print headers and current line as a recutil. (Use `indexed-times` so we can use the index to get the nth element from each array.) + +~~~ +:print-record + get-line s:to-array/csv !Current + @Headers a:length [ + I + dup @Headers swap a:fetch s:put ':_ s:put + @Current swap a:fetch s:put nl + ] indexed-times + ; +~~~ + +Now print-record for all the remaining lines in the file + +~~~ +[ + print-record nl + @size @handle file:tell gt? +] while +~~~ diff --git a/justfile b/justfile new file mode 100644 index 0000000..6ab743a --- /dev/null +++ b/justfile @@ -0,0 +1,15 @@ +# What's available here +default: + just --list + +# compile markdown to retro +compile: + echo "#!/usr/bin/env retro" > csv2recutil + echo "~~~" >> csv2recutil + retro-unu csv2recutil.md >> csv2recutil + echo "~~~" >> csv2recutil + chmod +x csv2recutil + +# search for and define a word +def: + echo "d:words" | retro | tail -n 1 | sed 's/\ /\n/g' | fzf | xargs retro-describe diff --git a/sample.csv b/sample.csv new file mode 100644 index 0000000..25ed4ac --- /dev/null +++ b/sample.csv @@ -0,0 +1,23 @@ +"Id","System","Module","Role","Format","Length","Status","Started","Updated","Notes" +"0","Dungeons & Dragons","Storm King's Thunder","DM","Roll20/Discord","Campaign","Hiatus","2020-04-02","2021-05-02","" +"1","Troika!","So You've Been Thrown Down A Well","DM","Play By Post","Adventure","Complete","2021","2021","" +"2","Troika!","Acid Death Fantasy","Player","Play By Post","Adventure","Dead","2021","2021-10-31","Update 2021-10-31 abandoned by gm after a valiant effort at keeping it going" +"3","Troika!","13 Story Bizarre","DM","Play By Post","One-Shot","Ongoing","2021","2021","Update 2021-10-31 Still going. Currently on level 8." +"4","Troika!","Dome Riders (Homebrew)","DM","Play By Post","Campaign","Hiatus","2021","2021","Update 2021-10-31 on hiatus" +"5","Wicked Ones (Forged in the Dark)","Homebrew","Player","Play By Post","Campaign?","Hiatus","2021","2021","Update 2021-10-31 on hiatus" +"6","Pathfinder","Agents of Edgewatch","Player","Roll20/Discord","Campaign","Ongoing","2021","2021","" +"7","Troika","Cocaine and Alligators: Florida Man Sphere","Player","zoom","One-Shot","Complete","2021-05-23","2021-05-23","Fun pick-up game from Melsonia discord. The game hilariously involves googling random Florida Man stories to create NPCs and encounters throughout the game. Could have honestly done without the whole police violence part in the middle. Good times overall though! I think this was my first time playing Troika in real time." +"8","Mothership","Picket Line Tango","Player","Play By Post","Adventure","Dead","2021-06-01","2021-10-31","Just started. Not much to report yet. Update 2021-10-31 Game stalled out really quickly, probably not going to pick back up" +"9","Mausritter","Honey Rafters","Player","Foundry/Discord","One-Shot","Complete","2021-06-07","2021-06-07","Fun game! Surprisingly spooky. Quite lethal. Cursed sunflower = corrupted bees and candy cultists. Played with FKR discord folk." +"10","Smithy of Sacrilege","Anvil (Homebrew)","Player","Play by Post","Campaign/Open Sandbox","Ongoing","2021-06-01","2021-06-07","A hack of Tunnel Goons by Nate Smith. Very fun original world, hex crawly open sandbox. You can get a lot done even with hyper minimal rules" +"11","Troika","Acid Death Fantasy","Player","Play by Post","Campaign","Ongoing","2021-09-16","2021-10-31","Another more different ADF! Born of the APF server, but on another new server with Kunailby. Playing Gliftwirp, a sarong-fu master who is also basically the hamburglar" +"12","Risus","To Kill A God","Player","Play by Post","Campaign","Ongoing","2021-08-24","2021-10-31","pbp on rpg.net with tibbius. Playing former child actor Sender, who is a blade for hire who just wants to retire and be a mushroom farmer, who is also haunted by the ghost of his dead twin brother who he absorbed in the womb, and who is also followed around by small woodland animals like a disney princess." +"13","Marvelous Mutations and Merry Musicians","Rockaway Beach","Player","Discord PBP","Adventures","Hiatus","2021-06-12","2021-10-31","wendi's game of mmnmm. almost immediately fizzled out. might resume at some point?" +"14","Cthulhu Dark","Garrets Ranch","Player","Zoom","Oneshot","Complete","2021-10-30","2021-10-31","Kyle ran us a game of Cthulhu Dark! Played with Josh and Mike and wendi. Investigate Garret's Ranch in Fate, Texas. Everybody escaped intact and alive. A very simple but very flexible game. I liked how you can boost your roll with a cost with the insight die. And we did a good job of using the failure die once or twice. Occupation is really important and you can kind of cripple yourself if you pick something off like ""uber driver"" like josh did. Nobody took advantage of infinite rolls, and I think somebody suppressed insight only once. Which is all to say that for a rules light game, you kind of have to remember a lot. Anyway, it was fun!" +"15","Troika","Moon's Shot","DM","Discord","Oneshot","Complete","2021-09-21","2021-10-31","Did moon's shot again but for the skookums-and-dragons crew. Zigs, Alex, and Jess. They murderhoboed the whole thing." +"16","Troika","Moon's Shot","DM","Zoom","Oneshot","Complete","2021-09-09","2021-10-31","ran moon's shot for alex, sparky, and jade. a good time was had by all. they did a capitalism, but for good" +"17","2-bit","Numenera","Player","Discord PBP","Adventure","Ongoing","2021-10-31","2021-10-31","gonna start a coin-flipping game with tibbius. gonna play a witchy person." +"18","troika","crapland 2","Player","Discord Jamboard","Oneshot","Complete","2021-11-05","2021-11-05","beautiful craptastic chaos at galgoricon 2021! Galgorian and Spooky Rusty ran a two table game with players constantly teleporting between the two locations before joining up at the final encounter. It was bonkers and fun. Big cast of characters, almost 12 players" +"19","D&D 5e","Zigs and Dragons","Player","Roll20 + Discord","Series","Ongoing","2021-12-03","2021-12-23","Zig's first time DM-ing! A series of oneshots on a mysterious island. Getting to play with Alex again is fun. The characters escalate from session to session from level 3 to 6 to 9 etc. Have played two so far. Having a lot of fun playing and getting to make new characters all the time." +"20","Giraffe Wants Best Leaves","Giraffe Wants Best Leaves","DM","jitsi -> mumble (technical issuse)","oneshot","Complete","2021-12-05","2021-12-05","This was a first, made a little toy rpg (a lasers and feelings clone) and some tildepals wanted to play it, so I ran a game for nico and malvarma. fun little session!" +"21","Into the Odd","yule homebrew","Player","Owlbear Rodeo + Zoom","oneshot","Complete","2021-12-21","2021-12-21","another Kyle game! got to play with eskur and wendi and kim. first time playing into the odd. played Luna Saturday, dreamy moonchild with a cane. we ventured down below a giant tree, and prevented a goblin invasion. (Wendi stopped the ooze ritual and tossed a bomb into the mirror.)"