-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 60de7cd
Showing
16 changed files
with
1,244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
labels: | ||
- "dependencies" | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
labels: | ||
- "dependencies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: build | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
go-version: [~1.17, ^1] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
GO111MODULE: "on" | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download Go modules | ||
run: go mod download | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: lint | ||
on: | ||
push: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
# Optional: allow read access to pull request. Use with `only-new-issues` option. | ||
pull-requests: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ^1 | ||
|
||
- uses: actions/checkout@v3 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Optional: golangci-lint command line arguments. | ||
#args: | ||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
only-new-issues: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# .github/workflows/release.yml | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
# run only against tags | ||
tags: | ||
- "*" | ||
|
||
permissions: | ||
contents: write | ||
# packages: write | ||
# issues: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Fetch all tags | ||
run: git fetch --force --tags | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: stable | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
distribution: goreleaser | ||
version: ${{ env.GITHUB_REF_NAME }} | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }} | ||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution: | ||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/go | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go | ||
|
||
### Go ### | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
env: | ||
- GO111MODULE=on | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- binary: Nachrichten | ||
flags: | ||
- -trimpath | ||
ldflags: -s -w -X main.Version={{ .Version }} -X main.CommitSHA={{ .Commit }} | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
- arm | ||
- arm64 | ||
goarm: | ||
- 6 | ||
- 7 | ||
|
||
nfpms: | ||
- builds: | ||
- Nachrichten | ||
vendor: Moooooritz | ||
homepage: "https://github.com/zMoooooritz" | ||
maintainer: "Moritz Biering <[email protected]>" | ||
description: "A TUI application to read German news" | ||
license: MIT | ||
formats: | ||
- apk | ||
- deb | ||
- rpm | ||
bindir: /usr/bin | ||
|
||
checksum: | ||
name_template: "checksums.txt" | ||
|
||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
|
||
changelog: | ||
use: github | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Moritz Biering | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
# Nachrichten | ||
|
||
A small TUI application that allows reading the current (German) news in the console. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
"log" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
"github.com/buger/jsonparser" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
const ( | ||
baseUrl string = "https://www.tagesschau.de/" | ||
apiUrl string = baseUrl + "api2u/homepage" | ||
shortNewsUrl string = baseUrl + "multimedia/sendung/tagesschau_in_100_sekunden" | ||
httpTimeout time.Duration = 2 | ||
agentName string = "Nachrichten-Agent" | ||
) | ||
|
||
type loadedNews News | ||
|
||
func getNews() tea.Cmd { | ||
return func() tea.Msg { | ||
body, err := fetchURL(apiUrl) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var news News | ||
err = json.Unmarshal(body, &news) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return loadedNews(news) | ||
} | ||
} | ||
|
||
func getShortNewsURL() (string, error) { | ||
body, err := fetchURL(shortNewsUrl) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(body)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
data, exists := doc.Find("div.teaser__media").Find("div.v-instance").Attr("data-v") | ||
if !exists { | ||
return "", errors.New("Unable to parse HTML to find URL") | ||
} | ||
|
||
url, err := jsonparser.GetString([]byte(data), "mc", "streams", "[0]", "media", "[4]", "url") | ||
if err != nil { | ||
return "", err | ||
} | ||
return url, nil | ||
} | ||
|
||
func fetchURL(url string) ([]byte, error) { | ||
client := http.Client{ | ||
Timeout: time.Second * httpTimeout, | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req.Header.Set("User-Agent", agentName) | ||
|
||
res, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.Body != nil { | ||
defer res.Body.Close() | ||
} | ||
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return body, nil | ||
} |
Oops, something went wrong.