2022-07-07 03:05:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"regexp"
|
2023-05-28 07:51:52 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
2022-07-07 03:05:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) != 3 {
|
2023-05-28 07:51:52 +00:00
|
|
|
fmt.Println("Usage: go run timestamps.go <fishbowl>.html <fishbowl>-timestamped.html")
|
2022-07-07 03:05:24 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
htmlPath := os.Args[1]
|
|
|
|
htmlOutPath := os.Args[2]
|
|
|
|
|
|
|
|
htmlBytes, err := os.ReadFile(htmlPath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
html := string(htmlBytes)
|
|
|
|
|
2023-05-28 07:51:52 +00:00
|
|
|
regex := regexp.MustCompile(
|
|
|
|
`(<span class="?chatlog__timestamp"?><a href=[^>]+>)(\d+)/(\d+)/(\d+)( [^<]+</a></span>)`,
|
2022-07-07 03:05:24 +00:00
|
|
|
)
|
|
|
|
|
2023-05-28 07:51:52 +00:00
|
|
|
htmlOut := regex.ReplaceAllStringFunc(html, func(s string) string {
|
|
|
|
match := regex.FindStringSubmatch(s)
|
|
|
|
month, err := strconv.ParseInt(match[2], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
monthStr := time.Month(month).String()
|
|
|
|
return fmt.Sprintf("%s%s %s, %s%s", match[1], monthStr, match[3], match[4], match[5])
|
|
|
|
})
|
2022-07-07 03:05:24 +00:00
|
|
|
|
|
|
|
err = os.WriteFile(htmlOutPath, []byte(htmlOut), 0666)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|