Skip to content

Commit

Permalink
Move repository
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-s committed Nov 20, 2017
1 parent 21cb537 commit b4552a2
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 223 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# google-drive
# spreadsheet-reader

## preparation

```
$ stack build
```

necessary environment variables
```
export SPREADSHEET_READER_REFRESH_TOKEN='your refresh token'
export SPREADSHEET_READER_CLIENT_ID='client_id'
export SPREADSHEET_READER_CLIENT_SECRET='client_secret'
```

## Usage

```
$ stack exec spreadsheet-reader-exe spreadsheetId range
```

example
```
$ stack exec spreadsheet-reader-exe 1-Ego70qG71GJjo3-NdAK8_8Xzxdot3qjz5dkYTenZ6k B2:D100
```
56 changes: 20 additions & 36 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module Main where

import Web.Spock
import Web.Spock.Config

import Control.Monad.Trans
import Data.Monoid
import Data.IORef
import qualified Data.Text as T
import Lib
import Spreadsheet.Reader
import System.Environment (getEnv, getArgs)
import Data.Aeson hiding(json)
import GHC.Generics

data MySession = EmptySession
data MyAppState = DummyAppState (IORef Int)

data SpreadsheetResult = SpreadsheetResult {
sheetresult :: [[T.Text]]
} deriving (Generic, Show)
instance ToJSON SpreadsheetResult
instance FromJSON SpreadsheetResult
import System.Environment (getEnv, getArgs)
import Data.Text

main :: IO ()
main = do
ref <- newIORef 0
spockCfg <- defaultSpockCfg EmptySession PCNoDatabase (DummyAppState ref)
runSpock 8081 (spock spockCfg app)
args <- getArgs
let sheetId = Prelude.head args
ranges = Prelude.last args
ranges' <- fetchValueRanges sheetId ranges
printAllValues ranges'

app :: SpockM () MySession MyAppState ()
app =
do get root $
text "Hello World!"
get ("hello" <//> var) $ \name ->
do (DummyAppState ref) <- getState
visitorNumber <- liftIO $ atomicModifyIORef' ref $ \i -> (i+1, i+1)
text ("Hello " <> name <> ", you are visitor number " <> T.pack (show visitorNumber))
printAllValues :: [[Text]] -> IO ()
printAllValues [x] = printValue x
printAllValues (x:xs) = do
let x = Prelude.head xs
printValue x
printAllValues xs

get ("spreadsheet" <//> var <//> var) $ \sheetId range ->
do (DummyAppState ref) <- getState
results <- liftIO $ fetchValueRanges (T.unpack sheetId) (T.unpack range)
json results
printValue :: [Text] -> IO ()
printValue x = do
let tl = Prelude.tail x
putStrLn $ Data.Text.unpack $ Prelude.head x
putStrLn $ Data.Text.unpack $ Prelude.head tl
putStrLn $ Data.Text.unpack $ Prelude.last tl
35 changes: 0 additions & 35 deletions google-drive.cabal

This file was deleted.

File renamed without changes.
30 changes: 0 additions & 30 deletions spreadsheet-reader/LICENSE

This file was deleted.

25 changes: 0 additions & 25 deletions spreadsheet-reader/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions spreadsheet-reader/Setup.hs

This file was deleted.

28 changes: 0 additions & 28 deletions spreadsheet-reader/app/Main.hs

This file was deleted.

Binary file removed spreadsheet-reader/src/Spreadsheet/.Reader.hs.swp
Binary file not shown.
66 changes: 0 additions & 66 deletions spreadsheet-reader/stack.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b4552a2

Please sign in to comment.