-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
45 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.