commit 7d06b6304edb3756fad579dbe0473a9148372f41 Author: h7x4 Date: Sun Mar 19 15:10:58 2023 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcfc4a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2dbe3c8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1678972866, + "narHash": "sha256-YV8BcNWfNVgS449B6hFYFUg4kwVIQMNehZP+FNDs1LY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cd34d6ed7ba7d5c4e44b04a53dc97edb52f2766c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "yokutango": "yokutango" + } + }, + "yokutango": { + "flake": false, + "locked": { + "lastModified": 1650838749, + "narHash": "sha256-N2GBldW3RITd5cWeRButiCAtAlcXaG7YMsxsuSMHffw=", + "ref": "master", + "rev": "a5d4ce3cdde942f07e76d40fb83d5b3e1dd5d20a", + "revCount": 41, + "type": "git", + "url": "https://git.nani.wtf/h7x4/yokutango" + }, + "original": { + "ref": "master", + "type": "git", + "url": "https://git.nani.wtf/h7x4/yokutango" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bd6a099 --- /dev/null +++ b/flake.nix @@ -0,0 +1,25 @@ +{ inputs = { + nixpkgs.url = "nixpkgs/nixos-22.11"; + yokutango = { + url = "git+https://git.nani.wtf/h7x4/yokutango?ref=master"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, yokutango }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system} = { + yokutango-json = pkgs.runCommandLocal "yokutango-json" {} '' + ln -s ${yokutango}/json $out + ''; + yokutango2tex = pkgs.writers.writeHaskell "yokutango2tex" { + libraries = with pkgs.haskellPackages; [ aeson bytestring ]; + } (pkgs.lib.fileContents ./yokutango2tex.hs); + yokutango-pdf = pkgs.runCommand "yokutango-pdf" {} '' + ${self.packages.${system}.yokutango2tex} ${self.packages.${system}.yokutango-json} + ''; + }; + }; +} diff --git a/yokutango2tex.hs b/yokutango2tex.hs new file mode 100644 index 0000000..8c9c558 --- /dev/null +++ b/yokutango2tex.hs @@ -0,0 +1,48 @@ +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DuplicateRecordFields #-} + +import Data.Aeson +import GHC.Generics +import System.Directory +import System.Environment +import System.FilePath + +import qualified Data.ByteString.Lazy as BS + +data NorwegianWord = NorwegianWord { word :: String + , hints :: Maybe [String] + } deriving (Generic, Show) + +instance FromJSON NorwegianWord +instance ToJSON NorwegianWord where + toEncoding = genericToEncoding defaultOptions + +data JapaneseWord = JapaneseWord { word :: String + , romaji :: Maybe String + , hints :: Maybe [String] + } deriving (Generic, Show) + +instance FromJSON JapaneseWord +instance ToJSON JapaneseWord where + toEncoding = genericToEncoding defaultOptions + +data Card = Card { norwegian :: [NorwegianWord] + , japanese :: [JapaneseWord] + } deriving (Generic, Show) + +instance FromJSON Card +instance ToJSON Card where + toEncoding = genericToEncoding defaultOptions + +readJsonFile :: FilePath -> IO (Either String [Card]) +readJsonFile path = eitherDecode <$> BS.readFile path + +main :: IO () +main = do + dir <- head <$> getArgs + filePaths <- map (\x -> joinPath [dir, x]) <$> listDirectory dir + jsonFiles <- mapM readJsonFile filePaths + -- case jsonFiles of + -- Right cards -> mapM_ print cards + -- Left err -> putStr err