packages feed

toboggan (empty) → 0.1.0.0

raw patch · 6 files changed

+169/−0 lines, 6 filesdep +basedep +clitdep +directorysetup-changed

Dependencies added: base, clit, directory, madlang, optparse-generic, text, toboggan

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Vanessa McHale (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Vanessa McHale nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,37 @@+## Toboggan - a twitter bot generator++### Horoscope example++This is an example of how to use the `Text.Madlibs` and `Web.Tweet` modules; primarily to showcase the Madlibs DSL. You can try a test tweet with++```+ $ toboggan --config configure/horoscope.mad --cred YOUR_CRED_FILE+```++You'll get a JSON-encoded response saying it all worked nicely if all goes well. If you like the results you can also get an example crontab for a daily bot that runs at 1pm with ++```+ $ toboggan --cron --config template.mad --cred credential+ +# m  h  dom mon dow   command  9 13  *   *   *    ~/.local/bin/toboggan --cred /home/user/programs/toboggan/credential --config /home/user/programs/toboggan/template.mad++(json response will be here)+```++### Installation++Install stack with++```+curl -sSL http://haskellstack.org | sh+```++and then use `stack install` to install. ++### Configuration++Configure using a `.cred` file as described in `Web.Tweet` [documentation](https://hackage.haskell.org/package/clit-0.2.0.1/docs/Web-Tweet.html). Use a Madlibs file to generate the bot text.++#### Editing++You'll probably want the [madlang-vim](http://github.com/vmchale/madlang-vim) if you use vim. 
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,6 @@+module Main where++import Web.Toboggan (act)++main :: IO ()+main = act
+ src/Web/Toboggan.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE TemplateHaskell   #-}+{-# LANGUAGE DeriveGeneric     #-}+{-# LANGUAGE TypeOperators     #-}+{-# LANGUAGE DataKinds         #-}+{-# LANGUAGE OverloadedStrings #-}++-- | Example that tweets from a "Madlibs" file.+module Web.Toboggan+    ( act+    , program+    , TwitterBot (..)+    ) where++import Text.Madlibs+import qualified Data.Text as T+import Web.Tweet+import Control.Monad+import System.Directory+import Options.Generic++-- | Data type for a twitter bot: configuration options and a CLI option+data TwitterBot = TwitterBot { config :: FilePath <?> "Path to the .mad template"+                             , cred   :: FilePath <?> "Path to credentials file"+                             , cron   :: Bool     <?> "Display example crontab for a twitter bot"+                             } deriving (Generic)++instance ParseRecord TwitterBot++-- | The command-line executable+act :: IO ()+act = do+    twitterBot <- getRecord "Twitter bot generator"+    program twitterBot++-- | Turn a `TwitterBot` into an IO action+program :: TwitterBot -> IO ()+program twitterBot = do+    let configR = unHelpful . config $ twitterBot+    horoscope <- runFile configR+    let credR = unHelpful . cred $ twitterBot+    if (unHelpful . cron $ twitterBot) then do+        dir <- getCurrentDirectory+        putStrLn (cronStr ++ "~/.local/bin/toboggan --cred " ++ dir ++ "/" ++ credR ++ " --config " ++ dir ++ "/" ++ configR ++ "\n")+    else+        pure ()+    void $ basicTweet (T.unpack horoscope) credR++-- | helper string for printing the crontab+cronStr :: String+cronStr = "\n# m  h  dom mon dow   command\+\  0 13  *   *   *    "
+ toboggan.cabal view
@@ -0,0 +1,43 @@+name: toboggan+version: 0.1.0.0+cabal-version: >=1.10+build-type: Simple+license: BSD3+license-file: LICENSE+copyright: Copyright: (c) 2016 Vanessa McHale+maintainer: tmchale@wisc.edu+homepage: https://github.com/vmchale/toboggan#readme+synopsis: Twitter bot generator+description:+    Please see README.md+category: Web+author: Vanessa McHale+extra-source-files:+    README.md++source-repository head+    type: git+    location: https://github.com/vmchale/toboggan++library+    exposed-modules:+        Web.Toboggan+    build-depends:+        base >=4.7 && <5,+        madlang >=0.1.0.1 && <0.2,+        clit >=0.2.0.0 && <0.3,+        text >=1.2.2.1 && <1.3,+        directory >=1.2.6.2 && <1.3,+        optparse-generic >=1.1.1 && <1.2+    default-language: Haskell2010+    hs-source-dirs: src++executable toboggan+    main-is: Main.hs+    build-depends:+        base >=4.9.0.0 && <4.10,+        toboggan >=0.1.0.0 && <0.2+    default-language: Haskell2010+    hs-source-dirs: app+    ghc-options: -threaded -rtsopts -with-rtsopts=-N+