Skip to content
Snippets Groups Projects
Commit 53fe1d3c authored by Felix Drees's avatar Felix Drees :penguin:
Browse files

Small update

parent ba46c3f2
No related branches found
No related tags found
1 merge request!1Small update
# FOOD PLAN GUI UNI HB (Haskell)
## quick start
---
- clone the repo
``` shell
git clone gitlab.informatik.uni-bremen.de/...
git clone git@gitlab.informatik.uni-bremen.de:fdrees/food-plan-hs.git
```
- change dir
......@@ -28,6 +31,8 @@ stack run
### install stack
---
>
>https://docs.haskellstack.org/en/stable/
>
......
......@@ -11,10 +11,11 @@ module Main (main) where
import qualified GI.Gtk as Gtk
import Data.GI.Base()
import Data.Text (Text)
import Data.Text (Text, pack, unpack)
import Data.Maybe
import Data.List()
import LibUniHbMensa as UM
import LibUniHbMensa as UniHbMensa
------ CONST VARS ------------------------------------------------------------
......@@ -33,21 +34,29 @@ mensaList = ["Uni Mensa",
------ HELPER FUNCs ----------------------------------------------------------
-- comboBoxHelper comBox strList = foldr Gtk.comboBoxTextAppendText comBox strList
comboBoxHelper :: Gtk.ComboBoxText -> [Text] -> IO ()
comboBoxHelper _ [] = return ()
comboBoxHelper comBox strList = do
Gtk.comboBoxTextAppendText comBox $ head strList
comboBoxHelper comBox $ tail strList
getMensaIdByText :: Text -> Int
getMensaIdByText name = getMensaIdByTextRec name 0
-- indexOf :: (Eq a) => a -> [a] -> Maybe Int
-- indexOf n xs = fmap snd . find (\ (x,_) -> x == n ) $ zip xs [0..]
{-----------------------------------------------------------------------------------------------------------------------
GET THE INDEX OF A SELECTED MENSA
If the Dininghall name is not part of the List the func will return Nothing, else the index of the element in the list.
-}
getMensaIdByText :: Text -> Maybe Int
getMensaIdByText t = if null results then Nothing else Just $ snd (head results)
where
getMensaIdByTextRec :: Text -> Int -> Int
getMensaIdByTextRec eman i
| (eman == (mensaList !! i)) = i
| otherwise = getMensaIdByTextRec eman (i + 1)
results = filter (\ (a,_) -> a == t) (zip mensaList [0..length mensaList])
{-----------------------------------------------------------------------------------------------------------------------
MAIN GUI
-}
main :: IO ()
main = do
......@@ -62,6 +71,7 @@ main = do
Gtk.setWindowDefaultHeight win 150
Gtk.setWindowWindowPosition win Gtk.WindowPositionCenter
Gtk.windowSetDecorated win True
-- TODO set icon to https://www.uni-bremen.de/favicon.ico
-- H1 LABEL ---------------------------------------------------------------
......@@ -72,6 +82,10 @@ main = do
cb <- Gtk.comboBoxTextNew
comboBoxHelper cb mensaList
-- newCb <- foldr Gtk.comboBoxTextAppendText Gtk.comboBoxTextNew mensaList
Gtk.comboBoxSetActive cb 0
-- SUBMIT BUTTON ----------------------------------------------------------
......@@ -84,7 +98,12 @@ main = do
currentCBText <- Gtk.comboBoxTextGetActiveText cb
putStrLn "--- URL ---"
print $ UM.getMensaWebpage $ if isJust currentCBText then getMensaIdByText (fromJust currentCBText) else 0 -- default id=0 for Uni Mensa
print $ UniHbMensa.getMensaWebpage $ if isJust currentCBText
then fromMaybe 0 (getMensaIdByText (fromJust currentCBText))
else 0
-- print UniHbMensa.getMensaWebpage $ fromMaybe 0 getMensaIdByText (currentCBText)
-- TODO display selected meal plan ...
......
......@@ -34,9 +34,11 @@ library
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base >=4.7 && <5
, bytestring
, gi-gtk ==3.0.*
, gi-gtk-hs
, haskell-gi-base
, http-conduit
, text
default-language: Haskell2010
......@@ -49,10 +51,12 @@ executable food-plan-hs-exe
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, bytestring
, food-plan-hs
, gi-gtk ==3.0.*
, gi-gtk-hs
, haskell-gi-base
, http-conduit
, text
default-language: Haskell2010
......@@ -66,9 +70,11 @@ test-suite food-plan-hs-test
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, bytestring
, food-plan-hs
, gi-gtk ==3.0.*
, gi-gtk-hs
, haskell-gi-base
, http-conduit
, text
default-language: Haskell2010
[Desktop Entry]
Name=food-plan-hs
Comment=GUI FOR UNI HB FOOD PLAN
Exec=/usr/local/bin/food-plan-hs
Icon=applications-other
Terminal=false
Type=Application
Categories=GTK;
Keywords=gui;mensa;food;
StartupNotify=true
......@@ -25,7 +25,8 @@ dependencies:
- gi-gtk-hs
- haskell-gi-base
- text
# http
- bytestring
- http-conduit
ghc-options:
- -Wall
......
......@@ -2,14 +2,22 @@
-- FOOD PLAN GUI - (c) 2022 Felix Drees - GNU GPLv3 --
-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module LibUniHbMensa where
-- import qualified Network.HTTP
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Char8 as LC
import Network.HTTP.Simple
--STATIC VARS------------------------------------------------------------------
baseUrl :: [Char]
baseUrl = "https://www.stw-bremen.de"
baseUrl = "http://www.stw-bremen.de" -- HTTP ONLY!
mensaUrlList :: [[Char]]
mensaUrlList = [
......@@ -29,11 +37,14 @@ mensaUrlList = [
getMensaWebpage :: Int -> String
getMensaWebpage mensaId
| (mensaId >= 0 && mensaId < length mensaUrlList) = getWebpage $ baseUrl ++ mensaUrlList !! mensaId
| otherwise = getWebpage $ baseUrl ++ mensaUrlList !! 0
| mensaId >= 0 && mensaId < length mensaUrlList = getWebpage $ baseUrl ++ mensaUrlList !! mensaId
| otherwise = getWebpage $ baseUrl ++ head mensaUrlList
where
getWebpage :: String -> String
getWebpage url = url
getWebpage url = url -- getResponseBody $ httpLBS url
-- getWebpage url = url -- HTTP_SIMP.getResponseBody $ HTTP_SIMP.httpLBS url
-- getWebpage url = simpleHTTP (getRequest url) >>= fmap (take 100) . getResponseBody
-- fetch document and return it (as a 'String'.)
-- https://hackage.haskell.org/package/HTTP-4000.3.16/docs/Network-HTTP.html
-- https://livebook.manning.com/book/get-programming-with-haskell/chapter-39/64
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment