Every like gives me a bigger pumpkin head
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

proto

+111 -31
+3 -1
.gitignore
··· 1 1 bighead 2 - .idea 2 + .idea 3 + .env 4 + pumpkin_head
+5
go.mod
··· 3 3 go 1.25.5 4 4 5 5 require golang.org/x/image v0.35.0 6 + 7 + require ( 8 + github.com/coder/websocket v1.8.14 // indirect 9 + github.com/joho/godotenv v1.5.1 // indirect 10 + )
+4
go.sum
··· 1 + github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g= 2 + github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg= 3 + github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= 4 + github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 1 5 golang.org/x/image v0.35.0 h1:LKjiHdgMtO8z7Fh18nGY6KDcoEtVfsgLDPeLyguqb7I= 2 6 golang.org/x/image v0.35.0/go.mod h1:MwPLTVgvxSASsxdLzKrl8BRFuyqMyGhLwmC+TO1Sybk=
+99 -30
main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "context" 4 5 "fmt" 5 6 "image" 6 7 "image/draw" 7 8 "image/jpeg" 8 9 "image/png" 10 + "log" 9 11 "os" 12 + "os/signal" 10 13 "path/filepath" 14 + "syscall" 15 + ) 11 16 17 + import ( 18 + "github.com/coder/websocket" 12 19 xdraw "golang.org/x/image/draw" 20 + 21 + "github.com/joho/godotenv" 13 22 ) 14 23 15 24 type PumpkinHead struct { ··· 17 26 headImg image.Image 18 27 callCount int 19 28 scaleStep float64 20 - outputDir string 29 + } 30 + 31 + func (p *PumpkinHead) Reset() { 32 + p.callCount = 0 33 + } 34 + 35 + func (p *PumpkinHead) GetCallCount() int { 36 + return p.callCount 21 37 } 22 38 23 - func NewPumpkinHead(bodyPath, headPath, outputDir string) (*PumpkinHead, error) { 39 + func NewPumpkinHead(bodyPath, headPath string) (*PumpkinHead, error) { 24 40 // Load body image 25 41 bodyFile, err := os.Open(bodyPath) 26 42 if err != nil { ··· 43 59 headImg, err := png.Decode(headFile) 44 60 if err != nil { 45 61 return nil, fmt.Errorf("failed to decode head image: %w", err) 46 - } 47 - 48 - // Create output directory if it doesn't exist 49 - if err := os.MkdirAll(outputDir, 0755); err != nil { 50 - return nil, fmt.Errorf("failed to create output directory: %w", err) 51 62 } 52 63 53 64 return &PumpkinHead{ 54 65 bodyImg: bodyImg, 55 66 headImg: headImg, 56 67 callCount: 0, 57 - scaleStep: 0.05, // How much my big head grows each call 58 - outputDir: outputDir, 68 + scaleStep: 0.01, // How much my big head grows each call 59 69 }, nil 60 70 } 61 71 ··· 96 106 return output, nil 97 107 } 98 108 99 - func main() { 100 - pumpkin, err := NewPumpkinHead("base_images/pumpkin_body_cropped.jpg", "base_images/better_pumpkin_head.png", "bighead") 109 + func saveToFiles(pumpkin *PumpkinHead, outputDir string, newPic image.Image) { 101 110 102 - if err != nil { 111 + // Create output directory if it doesn't exist 112 + if err := os.MkdirAll(outputDir, 0755); err != nil { 103 113 writeErrorAndExit(err) 104 114 } 105 115 106 - fmt.Println("Pumpkin Head Grower!") 107 - fmt.Println("==================") 108 - 109 - // Call the method 5 times to demonstrate 110 - for i := 0; i < 100; i++ { 111 - newPic, growingPains := pumpkin.GrowHead() 112 - if growingPains != nil { 113 - writeErrorAndExit(err) 114 - } 115 - 116 - saveToFiles(pumpkin, newPic) 117 - } 118 - 119 - fmt.Println("\nDone! Check the 'bighead' directory for results.") 120 - } 121 - 122 - func saveToFiles(pumpkin *PumpkinHead, newPic image.Image) { 123 116 // Save to file 124 - filename := filepath.Join(pumpkin.outputDir, fmt.Sprintf("bighead_%03d.png", pumpkin.callCount)) 117 + filename := filepath.Join(outputDir, fmt.Sprintf("bighead_%03d.png", pumpkin.callCount)) 125 118 outFile, err := os.Create(filename) 126 119 if err != nil { 127 120 writeErrorAndExit(err) ··· 141 134 } 142 135 os.Exit(1) 143 136 } 137 + 138 + func egoWatcher(ctx context.Context, conn *websocket.Conn, pumpkin *PumpkinHead) { 139 + for { 140 + _, _, err := conn.Read(ctx) 141 + if err != nil { 142 + if websocket.CloseStatus(err) == websocket.StatusNormalClosure { 143 + log.Println("Connection closed normally") 144 + return 145 + } 146 + log.Println("Read error:", err) 147 + return 148 + } 149 + 150 + fmt.Println("Someone liked one of your posts. Inflating ego") 151 + 152 + newHeadWhoDis, err := pumpkin.GrowHead() 153 + if err != nil { 154 + writeErrorAndExit(err) 155 + } 156 + saveToFiles(pumpkin, "bighead", newHeadWhoDis) 157 + 158 + //Incase i need to read the acutal record later 159 + //switch msgType { 160 + //case websocket.MessageText: 161 + // fmt.Printf("Received: %s\n", string(data)) 162 + //case websocket.MessageBinary: 163 + // fmt.Printf("Received binary: %d bytes\n", len(data)) 164 + //} 165 + } 166 + } 167 + 168 + func main() { 169 + 170 + err := godotenv.Load() 171 + if err != nil { 172 + writeErrorAndExit(err) 173 + } 174 + 175 + users_did := os.Getenv("DID") 176 + pds_host := os.Getenv("PDS_HOST") 177 + //app_password := os.Getenv("APP_PASSWORD") 178 + 179 + fmt.Println(users_did) 180 + fmt.Println(pds_host) 181 + //fmt.Println(app_password) 182 + 183 + spaceDustUrl := fmt.Sprintf("wss://spacedust.microcosm.blue/subscribe?wantedSubjectDids=%s&wantedSources=app.bsky.feed.like:subject.uri", users_did) 184 + 185 + pumpkin, err := NewPumpkinHead("base_images/pumpkin_body_cropped.jpg", "base_images/better_pumpkin_head.png") 186 + 187 + if err != nil { 188 + writeErrorAndExit(err) 189 + } 190 + 191 + fmt.Println("Pumpkin Head Grower!") 192 + fmt.Println("==================") 193 + 194 + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) 195 + defer stop() 196 + 197 + conn, _, err := websocket.Dial(ctx, spaceDustUrl, nil) 198 + if err != nil { 199 + log.Fatal(err) 200 + } 201 + defer conn.Close(websocket.StatusNormalClosure, "done") 202 + 203 + fmt.Println("Connected to spacedust!") 204 + 205 + // Start reading messages 206 + go egoWatcher(ctx, conn, pumpkin) 207 + 208 + // Wait for stop signal 209 + <-ctx.Done() 210 + 211 + fmt.Println("\nStopping... Check the 'bighead' directory for results.") 212 + }