Skip to content

Commit

Permalink
directory logger added
Browse files Browse the repository at this point in the history
  • Loading branch information
kociumba committed Sep 10, 2023
1 parent 714226c commit 6478cb0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
83 changes: 76 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"math"
"net/http"
"os"
Expand All @@ -15,14 +16,15 @@ import (
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/atotto/clipboard"

"github.com/wzshiming/ctc"

"github.com/mingrammer/cfmt"

"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/mem"

"github.com/wzshiming/ctc"
)

func main() {
Expand All @@ -37,7 +39,7 @@ func modeSelect() {

prompt := &survey.Select{
Message: "app mode:",
Options: []string{"sys info", "notes", "currency convert", "pricer", "fibonacci", "funny", "exit"},
Options: []string{"sys info", "notes", "currency converter", "list from directory", "time zone converter", "pricer", "fibonacci", "funny", "exit"},
}

survey.AskOne(prompt, &mode, survey.WithValidator(survey.Required))
Expand All @@ -50,12 +52,16 @@ func modeSelect() {
pricer()
case mode == "notes":
notes()
case mode == "list from directory":
listFromDirectory()
case mode == "messenger":
messenger()
case mode == "funny":
funny()
case mode == "sys info":
sysInfo()
case mode == "time zone converter":
timeZoneConvert()
case mode == "currency convert":
currencyConvert()
case mode == "fibonacci":
Expand All @@ -65,6 +71,7 @@ func modeSelect() {
case mode == "exit":
cfmt.Errorln("exiting...")
return

}
}

Expand Down Expand Up @@ -269,7 +276,7 @@ func addNote() {
return
}

notes()
// notes()
}

func readNotes() {
Expand Down Expand Up @@ -309,7 +316,7 @@ func readNotes() {
}
}

notes()
// notes()
}

func deleteNotes() {
Expand Down Expand Up @@ -355,7 +362,7 @@ func deleteNotes() {
deleter(notesToDelete)
}

notes()
// notes()
}

func deleter(notesToDelete []string) error {
Expand Down Expand Up @@ -386,7 +393,6 @@ func deleter(notesToDelete []string) error {
}
if !isMatched {
_, err := io.WriteString(tmpFile, line+"\n")

if err != nil {
fmt.Printf("error writing to temporary file: %v", err)
}
Expand Down Expand Up @@ -418,6 +424,45 @@ func deleter(notesToDelete []string) error {
return nil
}

func listFromDirectory() {
dir := ""
fileList := ""

prompt := &survey.Input{
Message: "select the directory (you can use env variables):",
Help: "this is the directory that will be read",
}

survey.AskOne(prompt, &dir, survey.WithValidator(survey.Required))

files, err := os.ReadDir(os.ExpandEnv(dir))
if err != nil {
log.Fatal(err)
}

outputFile, err := os.Create("fileList.txt")
if err != nil {
log.Fatal(err)
}
defer outputFile.Close()

for _, file := range files {
if file.IsDir() {
continue
}
outputFile.WriteString(file.Name() + "\n")
fileList += file.Name() + "\n"
}

err = clipboard.WriteAll(fileList)
if err != nil {
fmt.Println("Error copying to clipboard:", err)
return
}

log.Println("File names logged to fileList.txt and copied to clipboard")
}

func funny() {
type JokeResponse struct {
ID string `json:"id"`
Expand Down Expand Up @@ -485,6 +530,30 @@ func sysInfo() {

}

func timeZoneConvert() {

client := http.Client{}

requestFrom, err := http.NewRequest("GET", "https://worldtimeapi.org/api/timezone", nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}

resp, err := client.Do(requestFrom)
if err != nil {
fmt.Println(err)
}

defer resp.Body.Close()

var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)

fmt.Println(result)

}

func currencyConvert() {

amount := 0.0
Expand Down

0 comments on commit 6478cb0

Please sign in to comment.