Initial commit

This commit is contained in:
Oystein Kristoffer Tveit 2023-03-19 15:10:58 +01:00
commit 7d06b6304e
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
4 changed files with 118 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
result*

44
flake.lock generated Normal file
View File

@ -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
}

25
flake.nix Normal file
View File

@ -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}
'';
};
};
}

48
yokutango2tex.hs Normal file
View File

@ -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