Commit fad9d0d8 authored by HAMY's avatar HAMY

Updated to use new hashed ids in config and pulls down files into downloads/

parent f435f78d
hamynotes.txt
downloads/*
\ No newline at end of file
{
"mojiId": "cff80ec8-1754-4b9a-9238-3c3c4ae049be",
"comics": {
"birthday": [ "8fc50cb6-a2c5-4996-94d8-a8462cf5b66e" ],
"chill": [ "e560edcf-e7be-4344-9270-9d03e51a6b16" ],
"drink": [
"abc2240d-f3b9-4db2-ac54-09b9b53d0c1a",
"b78ef446-ee29-4953-810d-78fea164586c",
"09b2e9f7-3e3d-4434-b622-7ab757e0c352",
"69f2fc5d-1145-4232-8a67-f8ad35581c20",
"9c788ac1-c100-4981-830c-af4bd8e06d5d"
],
"drive": [ "395d53d1-7032-472e-9c34-fae7ebdae0e1" ],
"eat": [
"eb74f1ef-2129-48af-91f2-ed9d0c90db83",
"3241e7c5-b65a-49f9-b21c-06141f09c08c",
"51111bab-0d6f-445d-8b58-0b71142bf393",
"6e515ba6-ad8b-4a7e-ba4f-4e7f41fc233e",
"7c7fb00f-fe82-48bd-9df1-662d1eae123c",
"72ac9e93-804e-43eb-9e06-7270df7b4d41",
"d182ef3b-1d36-4fec-a420-d3b99896e54b",
"64632db1-ae50-4b61-b4b8-7bc582dfda3e",
"0dc5ffa2-6a92-45f3-a1cc-5a37b6485ab5",
"43206832-1550-473f-aeca-7032daf78ee3",
"1bf2b9d6-1622-498b-a2c0-af5431b08aa8",
"1a6bf39a-89ba-4fe5-ad1a-18a2d4fdbbc7",
"5a224a10-952e-4826-a4ee-919b23de2b52"
],
"explore": [
"0424dcbb-39cf-4a88-8703-1e58e0d3a306",
"b1beab9d-a87a-482f-8575-ed822ec70312",
"b3ca70b0-e7ab-4fd7-96b3-45af5dc1893a",
"d9cde183-a774-4088-b139-fe1359e4622b",
"a95db658-ab64-407c-ad67-8409dffc4426",
"66d5fd71-7794-46a1-896b-1d3503529f94"
],
"fly": [
"37c4322b-a978-4e5f-a632-4bdf2f969392",
"7b571e18-7246-4a8b-88aa-c954bc711d7a"
],
"projects": [ "5cdb5977-b8b9-4261-9f98-deef7c1bedee" ],
"run": [
"4fd49c6c-ce25-458f-9b32-eaea541f1922",
"5437b444-b1a2-4de5-be05-9bf5b21b09d1"
],
"shop": [ "3100d05d-6bcc-4850-a4e2-21022c66f35c" ],
"sleep": [
"3e14ad20-8fae-4e88-83b5-c04c00625d60",
"1148c694-2527-498b-bb87-d88a365463bd"
],
"yoga": [ "25306604-98ec-4068-90f1-e9129c7881d6" ]
},
"cPanelVersion": 1
}
\ No newline at end of file
package main
import "fmt"
import (
"fmt"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
)
func main() {
fmt.Printf("hello, world\n")
fmt.Printf("Initializing...\n")
fmt.Printf("Attempting open of config.json...\n")
jsonFile, err := os.Open("config.json")
if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()
fmt.Printf("Reading config.json into memory...\n")
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
fmt.Println(err)
}
// Initialize comics so we can read into it
var comics Comics
fmt.Printf("Unmarshaling json...\n")
json.Unmarshal(byteValue, &comics)
// fmt.Printf("mojiId: ")
// fmt.Println(comics.MojiId)
// fmt.Printf("\n")
var directoryPath string = "./downloads/" + comics.MojiId
// Check if directory exists
var _, statError = os.Stat(directoryPath)
if statError == nil {
fmt.Printf("There already exists a directory at %#v, exiting...", directoryPath)
return
}
fmt.Printf("Creating directory %#v...", comics.MojiId)
os.Mkdir(directoryPath, os.ModeDir)
// Iterate over keys in dict
// For key in dict, iterate over each file id
for k, v := range comics.Comics {
fmt.Printf("key found: %#v \n", k)
for _, comicId := range v {
// fmt.Printf("%#v", createBitMojiUrl(comics.MojiId, comic))
var downloadUrl = createBitMojiUrl(comics.MojiId, comicId)
writePath := directoryPath + "/" + comicId
err := downloadFile(downloadUrl, writePath)
if err != nil {
fmt.Println(err)
}
}
}
// Read in dict from config
// create subfolder for this id
// Parse over dict keys and download each from url, save with id name
// output dict that js can read with filepaths
// das it
}
\ No newline at end of file
}
func createBitMojiUrl(avatarId string, comicId string) string {
return "https://render.bitstrips.com/v2/cpanel/" + comicId + "-" + avatarId + "-v1.png?transparent=1&palette=1"
}
// Referenced from: https://golangcode.com/download-a-file-from-a-url/
func downloadFile(downloadUrl string, writePath string) error {
fmt.Printf("Attempting to create file at %#v", writePath)
out, err := os.Create(writePath)
if err != nil {
return err
}
defer out.Close()
response, err := http.Get(downloadUrl)
if err != nil {
return err
}
defer response.Body.Close()
_, err = io.Copy(out, response.Body)
if err != nil {
return err
}
return nil
}
type Comics struct {
MojiId string `json:"mojiId"`
Comics map[string][]string `json:"comics"`
}
// https://render.bitstrips.com/render/comicId/avatarId-v3.png?transparent=1&scale=1
// https://render.bitstrips.com/v2/cpanel/comicId/avatarId-v3.png?transparent=1&scale=1
// MyId: cff80ec8-1754-4b9a-9238-3c3c4ae049be
// First: https://render.bitstrips.com/v2/cpanel/3241e7c5-b65a-49f9-b21c-06141f09c08c-cff80ec8-1754-4b9a-9238-3c3c4ae049be-v1.png?transparent=1&palette=1
// Second https://render.bitstrips.com/v2/cpanel/0424dcbb-39cf-4a88-8703-1e58e0d3a306-cff80ec8-1754-4b9a-9238-3c3c4ae049be-v1.png?transparent=1&palette=1
// Stuffl https://render.bitstrips.com/v2/cpanel/6e515ba6-ad8b-4a7e-ba4f-4e7f41fc233e-cff80ec8-1754-4b9a-9238-3c3c4ae049be-v1.png?transparent=1&palette=1
// kebabMe: https://render.bitstrips.com/v2/cpanel/3241e7c5-b65a-49f9-b21c-06141f09c08c-cff80ec8-1754-4b9a-9238-3c3c4ae049be-v1.png?transparent=1&palette=1
// kebabDan https://render.bitstrips.com/v2/cpanel/3241e7c5-b65a-49f9-b21c-06141f09c08c-f5fbfd47-f0c9-4257-b317-d7cd37c81010-v1.png?transparent=1&palette=1
// kebabBob
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment