1
0

Zaktualizuj 'Projekt1/zadanie.go'

This commit is contained in:
Łukasz Korbanek 2019-03-08 20:24:17 +00:00
parent 8bd6891d74
commit e7ae41ca37

View File

@ -1,105 +1,105 @@
package main package main
import ( import (
"fmt" "fmt"
"time" "time"
"color" "github.com/fatih/color"
"io/ioutil" "io/ioutil"
"bufio" "bufio"
"os" "os"
"strings" "strings"
) )
func main() { func main() {
p := fmt.Println p := fmt.Println
now := time.Now() now := time.Now()
blue := color.New(color.FgBlue) blue := color.New(color.FgBlue)
wheBackground := blue.Add(color.BgWhite) wheBackground := blue.Add(color.BgWhite)
wheBackground.Println(" TODAY IS: ") wheBackground.Println(" TODAY IS: ")
p(" ",now.Weekday(),"|",now.Day(),now.Month(),now.Year()) p(" ",now.Weekday(),"|",now.Day(),now.Month(),now.Year())
white := color.New(color.FgWhite) white := color.New(color.FgWhite)
MagentaBackground := white.Add(color.BgMagenta) MagentaBackground := white.Add(color.BgMagenta)
MagentaBackground.Println("\nMED 6:00 14:00 22:00") MagentaBackground.Println("\nMED 6:00 14:00 22:00")
if int(now.Weekday()) == int(1) { if int(now.Weekday()) == int(1) {
data, err := ioutil.ReadFile("1.txt") data, err := ioutil.ReadFile("1.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(2) { if int(now.Weekday()) == int(2) {
data, err := ioutil.ReadFile("2.txt") data, err := ioutil.ReadFile("2.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(3) { if int(now.Weekday()) == int(3) {
data, err := ioutil.ReadFile("3.txt") data, err := ioutil.ReadFile("3.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(4) { if int(now.Weekday()) == int(4) {
data, err := ioutil.ReadFile("4.txt") data, err := ioutil.ReadFile("4.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(5) { if int(now.Weekday()) == int(5) {
data, err := ioutil.ReadFile("5.txt") data, err := ioutil.ReadFile("5.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(6) { if int(now.Weekday()) == int(6) {
data, err := ioutil.ReadFile("6.txt") data, err := ioutil.ReadFile("6.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
if int(now.Weekday()) == int(0) { if int(now.Weekday()) == int(0) {
data, err := ioutil.ReadFile("7.txt") data, err := ioutil.ReadFile("7.txt")
if err != nil { if err != nil {
p("Error", err) p("Error", err)
return return
} }
p(string(data)) p(string(data))
} else { } else {
p("Error") p("Error")
} }
} }
} }
} }
} }
} }
} }
red := color.New(color.FgRed) red := color.New(color.FgRed)
whiteBackground := red.Add(color.BgWhite) whiteBackground := red.Add(color.BgWhite)
whiteBackground.Println("\n NEXT WEEK YOU'LL RUN OUT OF: ") whiteBackground.Println("\n NEXT WEEK YOU'LL RUN OUT OF: ")
fileHandle, _ := os.Open("meds.txt") fileHandle, _ := os.Open("meds.txt")
defer fileHandle.Close() defer fileHandle.Close()
fileScanner := bufio.NewScanner(fileHandle) fileScanner := bufio.NewScanner(fileHandle)
for fileScanner.Scan() { for fileScanner.Scan() {
if strings.HasSuffix(fileScanner.Text(), ":0") == true { if strings.HasSuffix(fileScanner.Text(), ":0") == true {
p(" ",fileScanner.Text())} p(" ",fileScanner.Text())}
} }
} }