Skip to content

Commit

Permalink
Random README
Browse files Browse the repository at this point in the history
  • Loading branch information
CrosleyZack committed Oct 12, 2024
1 parent d1cb2a8 commit d06b7e5
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create README
description: Create README
on:
workflow_dispatch:
push:
branches:
- master
schedule:
- cron: "0 0 * * *"
jobs:
make-wallpaper:
name: "Generate the README"
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- name: Install requirements
run: go run main.go
- run: |
git config user.name crosleyzack
git config user.email [email protected]
git add -f README.md
git diff --quiet && git diff --staged --quiet || git commit -m "[gh-action] Daily Wallpaper"
git push origin main
98 changes: 98 additions & 0 deletions README.base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<img src="landscape.gif" width="100%" height="100%">
<!-- Credit to W00kieetreiber @ https://www.reddit.com/r/Firewatch/comments/s9m7b1/i_made_this/ for gif -->

<!-- Credit to alexandresanlim @ https://github.com/alexandresanlim/Badges4-README.md-Profile for badges -->
<p align='center'>

<a href="https://www.linkedin.com/in/crosleyzack/">
<img src="https://img.shields.io/badge/linkedin-%230077B5.svg?&style=for-the-badge&logo=linkedin&logoColor=white" />
</a>
&nbsp;&nbsp;
<a href="https://crosleyzack.com">
<img src="https://img.shields.io/badge/website-222222?style=for-the-badge&logo=githubpages&logoColor=white" />
</a>
&nbsp;&nbsp;
<!-- TODO update with proper URI later -->
<a href="https://signal.me/#eu/19hMy6iGDXwaBMNL0wdNbtf5alA5P9j3JkJSp//lHrHXtawqWEROWK1MatAWsUz1">
<img src="https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white" />
</a>
<!--<img src="https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white" onmouseover="this.src='https://img.shields.io/badge/crosleyzack.01-3A76F0?style=for-the-badge&logo=signal&logoColor=white'" onmouseout="this.src='https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white'" />-->
</p>

---


<p align='center'>
<img src="https://img.shields.io/badge/go-00ADD8?style=for-the-badge&logo=go&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/python-3776AB?style=for-the-badge&logo=python&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/c++-00599C?style=for-the-badge&logo=cplusplus&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/clojure-5881D8?style=for-the-badge&logo=clojure&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/julia-9558B2?style=for-the-badge&logo=julia&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/typescript-3178C6?style=for-the-badge&logo=typescript&logoColor=white" />

<br >

<img src="https://img.shields.io/badge/gcloud-4285F4?style=for-the-badge&logo=googlecloud&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/pubsub-90B0E0?style=for-the-badge&logo=googlepubsub&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/postgresql-4169E1?style=for-the-badge&logo=postgresql&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/docker-2CA5E0?style=for-the-badge&logo=docker&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/kubernetes-326CE5?style=for-the-badge&logo=kubernetes&logoColor=white" />
<!-- <img src="https://img.shields.io/badge/django-092E20?style=for-the-badge&logo=django&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/latex-008080?style=for-the-badge&logo=latex&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/yubico-84BD80?style=for-the-badge&logo=yubico&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/wappalyzer-4608AD?style=for-the-badge&logo=wappalyzer&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/redis-DC382D?style=for-the-badge&logo=redis&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/scala-DC322F?style=for-the-badge&logo=scala&logoColor=white" /> -->


<br >

<img src="https://img.shields.io/badge/git-E44C30?style=for-the-badge&logo=git&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/vscode-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/bash-4EAA25?style=for-the-badge&logo=gnubash&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/VIM-%2311AB00.svg?&style=for-the-badge&logo=vim&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/tmux-1BB915?style=for-the-badge&logo=tmux&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/linux-E0B020?style=for-the-badge&logo=linux&logoColor=white" />
<!-- <img src="https://img.shields.io/badge/xorg-F28834?style=for-the-badge&logo=xdotorg&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/wayland-F0B000?style=for-the-badge&logo=wayland&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/Debian-A81D33?style=for-the-badge&logo=debian&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/fedora-51A2DA?style=for-the-badge&logo=fedora&logoColor=white" /> -->
</p>

<!-- [Public Key](key.pub) -->

<!--
To make new badges, use:
https://img.shields.io/badge/Google%20Cloud-4285F4?style=for-the-badge&logo=googlecloud&logoColor=white
|--- String --| |color| |simple-icon-name| |icon-color|
find icons at https://simpleicons.org/
-->

<!-- Custom logo example
|-badge text-| |color| |----style----|
https://img.shields.io/badge/with%20a%20logo-8A2BE2?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEiIHdpZHRoPSI2MDAiIGhlaWdodD0iNjAwIj48cGF0aCBkPSJNMTI5IDExMWMtNTUgNC05MyA2Ni05MyA3OEwwIDM5OGMtMiA3MCAzNiA5MiA2OSA5MWgxYzc5IDAgODctNTcgMTMwLTEyOGgyMDFjNDMgNzEgNTAgMTI4IDEyOSAxMjhoMWMzMyAxIDcxLTIxIDY5LTkxbC0zNi0yMDljMC0xMi00MC03OC05OC03OGgtMTBjLTYzIDAtOTIgMzUtOTIgNDJIMjM2YzAtNy0yOS00Mi05Mi00MmgtMTV6IiBmaWxsPSIjZmZmIi8+PC9zdmc+
|--------------------------------------------- BASE64 SVG ICON -------------------
-->

### Random Encounter

<details>
<p align="center">
<img src="{{pokemon}}" alt="Random Pokemon" height="100" width="100" />
</p>
</details>
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ find icons at https://simpleicons.org/
https://img.shields.io/badge/with%20a%20logo-8A2BE2?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEiIHdpZHRoPSI2MDAiIGhlaWdodD0iNjAwIj48cGF0aCBkPSJNMTI5IDExMWMtNTUgNC05MyA2Ni05MyA3OEwwIDM5OGMtMiA3MCAzNiA5MiA2OSA5MWgxYzc5IDAgODctNTcgMTMwLTEyOGgyMDFjNDMgNzEgNTAgMTI4IDEyOSAxMjhoMWMzMyAxIDcxLTIxIDY5LTkxbC0zNi0yMDljMC0xMi00MC03OC05OC03OGgtMTBjLTYzIDAtOTIgMzUtOTIgNDJIMjM2YzAtNy0yOS00Mi05Mi00MmgtMTV6IiBmaWxsPSIjZmZmIi8+PC9zdmc+
|--------------------------------------------- BASE64 SVG ICON -------------------
-->

### Random Encounter

<details>
<p align="center">
<img src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/326.png" alt="Random Pokemon" height="100" width="100" />
</p>
</details>
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/crosleyzack/crosleyzack

go 1.22.7
118 changes: 118 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"embed"
"encoding/json"
"fmt"
"io"
"log"
"math/rand/v2"
"net/http"
"os"
"strings"
)

//go:embed README.base.md
var fs embed.FS

func getPokemonNumber() int {
// first four gens, because they are the best
return rand.IntN(494)
}

func isShiny() bool {
// https://bulbapedia.bulbagarden.net/wiki/Shiny_Pok%C3%A9mon
return rand.IntN(65536) < 16
}

// Sprites is a struct that contains the URLs for the different sprites of a pokemon
type Sprites struct {
FrontDefault string `json:"front_default"`
FrontFemale string `json:"front_female"`
FrontShiny string `json:"front_shiny"`
FrontShinyFemale string `json:"front_shiny_female"`
}

func (s Sprites) hasGenderedForm() bool {
return s.FrontFemale != "" && s.FrontShinyFemale != ""
}

func (s Sprites) getSprite(male bool, shiny bool) (uri string) {
if shiny {
switch male {
case true:
uri = s.FrontShiny
default:
uri = s.FrontShinyFemale
}
} else {
switch male {
case true:
uri = s.FrontDefault
default:
uri = s.FrontFemale
}
}
return uri
}

// Pokemon is a struct that contains the name and sprites of a pokemon
type Pokemon struct {
Name string `json:"name"`
Sprites Sprites `json:"sprites"`
}

func getPokemon(number int) (*Pokemon, error) {
requestURL := fmt.Sprintf("https://pokeapi.co/api/v2/pokemon/%d", number)
resp, err := http.Get(requestURL)
if err != nil {
return nil, fmt.Errorf("error making http request: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("error getting pokemon: %s", resp.Status)
}
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
var pokemon Pokemon
err = json.Unmarshal(bodyBytes, &pokemon)
if err != nil {
return nil, fmt.Errorf("error unmarshalling response body: %w", err)
}
return &pokemon, nil
}

func getSprite(pokemon *Pokemon) string {
male := true
if pokemon.Sprites.hasGenderedForm() {
male = rand.Float32() < 0.5
}
return pokemon.Sprites.getSprite(male, isShiny())
}

func getRandomEncounter() (string, error) {
pokemon, err := getPokemon(getPokemonNumber())
if err != nil {
return "", fmt.Errorf("error getting pokemon: %w", err)
}
return getSprite(pokemon), nil
}

// main loads root command from cmds package and executes it
func main() {
encounter, err := getRandomEncounter()
if err != nil {
log.Fatal(err)
}
readme, err := fs.ReadFile("README.base.md")
if err != nil {
log.Fatal(err)
}
newREADME := strings.Replace(string(readme), "{{pokemon}}", encounter, 1)
if err := os.WriteFile("README.md", []byte(newREADME), 0666); err != nil {
log.Fatal(err)
}
return
}

0 comments on commit d06b7e5

Please sign in to comment.