-
Notifications
You must be signed in to change notification settings - Fork 0
/
GF-loves-food.hs
38 lines (34 loc) · 1.02 KB
/
GF-loves-food.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import PGF
import System.Random
import System.IO
import Data.Time.Clock.POSIX
import System.CPUTime
import Twitter
import Network.HTTP.Client
import Data.ByteString.Lazy.Char8 hiding (putStrLn, length, head)
selectRandom :: RandomGen g => [a] -> g -> (a, g)
selectRandom list rnd =
let
(rndNum,newRnd) = randomR (0,(length list - 1)) rnd
elem = list!!rndNum
in
(elem, newRnd)
generate :: RandomGen g => PGF -> g -> (String,g)
generate pgf rnd =
let
gen = generateRandom rnd pgf (startCat pgf)
(lang,newRnd) = (selectRandom (languages pgf) rnd)
s = linearize pgf lang (head gen)
in
(s,newRnd)
main =
do
pgf <- readPGF "Foods.pgf"
conf <- configFromFile "config.json"
time <- round `fmap` getPOSIXTime
cpuptime <- getCPUTime
let cputime = cpuptime `div` 100000000
let rnd = mkStdGen (fromInteger (toInteger (time + cputime) ) )
let (s,newRnd) = generate pgf rnd
putStrLn s
either putStrLn (\c -> tweet c s >>= putStrLn . unpack . responseBody >> return () ) conf