Skip to content

Instantly share code, notes, and snippets.

@APratham
Created March 23, 2021 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save APratham/c22f37e141d1794aeeb46d931f42b045 to your computer and use it in GitHub Desktop.
Save APratham/c22f37e141d1794aeeb46d931f42b045 to your computer and use it in GitHub Desktop.
AutoUpdate
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
"strings"
"time"
)
func makeReadme(filename string) error {
// Read entire file content, giving us little control but
// making it very simple. No need to close the file.
content, err := ioutil.ReadFile("facts.txt")
if err != nil {
log.Fatal(err)
}
// Convert []byte to string and print to screen
// text := string(content)
// fmt.Println(text)
rand.Seed(time.Now().UnixNano())
str := string(content)
fact := rand.Intn(len(content))
lines := strings.Split(string(str), "\n")
date := time.Now().Format("2 Jan 2006")
hello := "### Hello! I’m Antariksh Pratham."
quote := "⚡ Fun fact: " + lines[fact]
updated := "<sub>Last updated by magic on " + date + ".</sub>"
data := fmt.Sprintf("%s\n\n%s\n\n%s\n", hello, quote, updated)
@APratham
Copy link
Author

Error screenshot
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment