Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
🧱 Cleaned up with Deepsource [see desc]
Browse files Browse the repository at this point in the history
 - `strings.Replace`, -1 -> `strings.ReplaceAll` 
 - Fix spacing
 - Sort imports

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
deepsource-autofix[bot] authored Sep 19, 2022
1 parent 7b906fa commit d88c5e7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

// Import pkgs
import (
"log"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
Expand All @@ -13,13 +13,13 @@ import (
"github.com/charmbracelet/lipgloss"

"github.com/charmbracelet/bubbles/viewport"
"github.com/knipferrc/teacup/statusbar"
"github.com/charmbracelet/glamour"

"github.com/knipferrc/teacup/statusbar"

md "github.com/JohannesKaufmann/html-to-markdown"
)

const lang = "en" // Lang prefix used on
const lang = "en" // Lang prefix used on
const apiURL = "https://" + lang + ".wikipedia.org/api/rest_v1/" // Wikipedia API URL
const useHighPerformanceRenderer = false

Expand All @@ -29,7 +29,7 @@ type Bubble struct {
viewport viewport.Model
height int
content string
title string
title string
articleName string
ready bool
}
Expand Down Expand Up @@ -127,7 +127,6 @@ func (b Bubble) footerView() string {
return b.statusbar.View()
}


func main() {
article := ""
saveToFile := false
Expand All @@ -150,29 +149,29 @@ func main() {
log.Fatal(err)
os.Exit(1)
}

cont, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
os.Exit(1)
}

converter := md.NewConverter("", true, nil)
content, err := converter.ConvertString(strings.Replace(string(cont), "//upload.wikimedia.org", "https://upload.wikimedia.org", -1))
content, err := converter.ConvertString(strings.ReplaceAll(string(cont), "//upload.wikimedia.org", "https://upload.wikimedia.org"))
if err != nil {
log.Fatal(err)
os.Exit(1)
}

out, err := glamour.Render(content, "dark")

if err != nil {
log.Fatal(err)
os.Exit(1)
}

if saveToFile {
f, err := os.OpenFile(article + ".md", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
f, err := os.OpenFile(article+".md", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
Expand All @@ -184,11 +183,11 @@ func main() {
}
} else {
p := tea.NewProgram(
Bubble{statusbar: NewStatusbar(), content: string(out), title: "Wiki CLI", articleName: strings.Replace(article, "_", " ", -1)},
Bubble{statusbar: NewStatusbar(), content: string(out), title: "Wiki CLI", articleName: strings.ReplaceAll(article, "_", " ")},
tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"
tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
)

if err := p.Start(); err != nil {
fmt.Println("could not run program:", err)
os.Exit(1)
Expand Down

0 comments on commit d88c5e7

Please sign in to comment.