Add fishbowl tools (#64)

Reducing the bus factor.

Top-level directory is likely not the best place for those, open to suggestions.

Co-authored-by: Ilia Demianenko <ilia.demianenko@gmail.com>
Reviewed-on: #64
Co-authored-by: ilidemi <belk94@gmail.com>
Co-committed-by: ilidemi <belk94@gmail.com>
pull/71/head
ilidemi 3 months ago committed by Ben Visness
parent d01731f4cd
commit 7ba8df3942
  1. 1
      fishbowl-tools/.gitignore
  2. 10
      fishbowl-tools/.vscode/fishbowl.code-snippets
  3. 65
      fishbowl-tools/steps.md
  4. 41
      fishbowl-tools/timestamps.go
  5. 77
      fishbowl-tools/twemoji.go

@ -0,0 +1 @@
!.vscode

@ -0,0 +1,10 @@
{
"Resource Link": {
"prefix": [
"hmn-link"
],
"body": [
"<a class=\"inserted-after\" href=\"$1\" target=\"_blank\">$TM_SELECTED_TEXT</a>"
]
}
}

@ -0,0 +1,65 @@
- [ ] Export with [DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter) CLI 2.34
```
DiscordChatExporter.Cli.exe export -c [thread-id] -t [token] -o [fishbowl].html --media
```
- [ ] Rename `[fishbowl].html_Files` to `files`, replace links in html
- [ ] Add target="_blank" to links
```
(a href="[^"]+")>
$1 target="_blank">
```
- [ ] Add JQuery to `<head>`
```html
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script>
$( function() {
$( ".chatlog" ).sortable();
} );
</script>
```
- [ ] Drag/delete noise/edit in the browser
- [ ] Save as `[fishbowl]-dragged.html` (devtools -> `<html>` -> copy outerHTML)
- [ ] Remove JQuery, sortable classes
```
ui-sortable
ui-sortable-handle
```
- [ ] Check `#fishbowl-audience` for highlights
- [ ] Fix audience avatar paths if anything copied
- [ ] Fix bad pictures (composite emojis 404)
- [ ] Fix links with extra braces at the end
```
href="[^"]+\)"
```
- [ ] Fill in resource links with vscode snippet (select phrase, Ctrl+Shift+P -> Insert Snippet -> hmn-link, paste the url)
- [ ] Download twemojies
```
go run twemoji.go [fishbowl]-dragged.html files [fishbowl]-twemojied.html
```
- [ ] Fix timestamps
```
go run timestamps.go [fishbowl]-twemojied.html [fishbowl]-timestamped.html
```
- [ ] Create a branch off latest `hmn` master
- [ ] Create fishbowl folder under `hmn/src/templates/src/fishbowls/`
- [ ] Copy timestamped html and files, rename html
- [ ] Remove everything from html but chatlog
- [ ] Remove js, css and whitney from files
- [ ] Add content path to `fishbowl.go`
- [ ] Test locally
- [ ] Submit a pull request

@ -0,0 +1,41 @@
package main
import (
"fmt"
"os"
"regexp"
)
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: go run timestamps.go [fishbowl].html [fishbowl]-timestamped.html")
os.Exit(1)
}
htmlPath := os.Args[1]
htmlOutPath := os.Args[2]
htmlBytes, err := os.ReadFile(htmlPath)
if err != nil {
panic(err)
}
html := string(htmlBytes)
regex, err := regexp.Compile(
"(<span class=\"chatlog__timestamp\">)(\\d+)-([A-Za-z]+)-(\\d+)( [^<]+</span>)",
)
if err != nil {
panic(err)
}
htmlOut := regex.ReplaceAllString(
html,
"$1$3 $2, 20$4$5",
)
err = os.WriteFile(htmlOutPath, []byte(htmlOut), 0666)
if err != nil {
panic(err)
}
}

@ -0,0 +1,77 @@
package main
import (
"fmt"
"io"
"net/http"
"os"
"path"
"strings"
)
func main() {
if len(os.Args) != 4 {
fmt.Println("Usage: go run twemoji.go [fishbowl].html files [fishbowl]-twemojied.html")
os.Exit(1)
}
htmlPath := os.Args[1]
filesDir := os.Args[2]
htmlOutPath := os.Args[3]
htmlBytes, err := os.ReadFile(htmlPath)
if err != nil {
panic(err)
}
html := string(htmlBytes)
for {
linkStart := strings.Index(html, "https://twemoji.maxcdn.com/")
if linkStart == -1 {
break
}
linkEnd := strings.Index(html[linkStart:], "\"") + linkStart
link := html[linkStart:linkEnd]
emojiFilenameStart := strings.LastIndex(link, "/") + 1
emojiFilename := "twemoji_" + link[emojiFilenameStart:]
emojiPath := path.Join(filesDir, emojiFilename)
emojiResponse, err := http.Get(link)
if err != nil {
panic(err)
}
defer emojiResponse.Body.Close()
if emojiResponse.StatusCode > 299 {
panic("Non-200 status code: " + fmt.Sprint(emojiResponse.StatusCode))
}
emojiFile, err := os.Create(emojiPath)
if err != nil {
panic(err)
}
defer emojiFile.Close()
_, err = io.Copy(emojiFile, emojiResponse.Body)
if err != nil {
panic(err)
}
html = strings.ReplaceAll(html, link, emojiPath)
fmt.Println(emojiFilename)
}
html = strings.ReplaceAll(
html,
"<div class=\"chatlog\">",
"<div class=\"chatlog\">\n<!-- Emojis by Twitter's Twemoji https://twemoji.twitter.com/ -->",
)
err = os.WriteFile(htmlOutPath, []byte(html), 0666)
if err != nil {
panic(err)
}
}
Loading…
Cancel
Save