Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10669663
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
View Options
diff --git a/import.go b/import.go
index 8e2bcf4..3a54b87 100644
--- a/import.go
+++ b/import.go
@@ -1,61 +1,108 @@
package writefreely
import (
- "archive/zip"
+ "encoding/json"
"fmt"
- "io"
- "log"
+ "io/ioutil"
"os"
)
+type userInfo struct {
+ Username string `json:"username"`
+ HasPass bool `json:"has_pass"`
+ Email string `json:"email"`
+ Created string `json:"created"`
+ Collections []importCollection `json:"collections"`
+}
+
type importCollection struct {
- Alias string `json: "alias"`
- Title string `json: "title"`
+ Alias string `json:"alias"`
+ Title string `json:"title"`
Description string `json:"description"`
StyleSheet string `json:"style_sheet"`
Public bool `json:"public"`
Views int `json:"views"`
URL string `json:"url"`
Total int `json:"total_posts"`
Posts []post `json:"posts"`
}
type post struct {
- Id string `json:"id"`
+ ID string `json:"id"`
Slug string `json:"slug"`
Appearance string `json:"appearance"`
Language string `json:"language"`
Rtl bool `json:"rtl"`
Created string `json:"created"`
Updated string `json:"updated"`
Title string `json:"title"`
Body string `json:"body"`
Tags []string `json:"tags"`
Views int `json:"views"`
}
-func zipreader(src string) ([]string, error) {
-
- // Open a zip archive for reading.
- r, err := zip.OpenReader("testdata/readme.zip")
+func jsonReader() {
+ // Open our jsonFile
+ jsonFile, err := os.Open("skye-201905250022.json")
+ // if we os.Open returns an error then handle it
if err != nil {
- log.Fatal(err)
- }
- defer r.Close()
-
- // Iterate through the files in the archive,
- // printing some of their contents.
- for _, f := range r.File {
- fmt.Printf("Contents of %s:\n", f.Name)
- rc, err := f.Open()
- if err != nil {
- log.Fatal(err)
- }
- _, err = io.CopyN(os.Stdout, rc, 68)
- if err != nil {
- log.Fatal(err)
- }
- rc.Close()
- fmt.Println()
+ fmt.Println(err)
}
+ fmt.Println("Successfully Opened users.json")
+ // defer the closing of our jsonFile so that we can parse it later on
+ defer jsonFile.Close()
+
+ // read our opened xmlFile as a byte array.
+ byteValue, _ := ioutil.ReadAll(jsonFile)
+
+ // we initialize our collections array
+ var u userInfo
+
+ // we unmarshal our byteArray which contains our
+ // jsonFile's content into 'users' which we defined above
+ json.Unmarshal(byteValue, &u)
+ fmt.Println(u.Collections[0].Posts)
+
+ return
+ // for _, p := range u.Collections[0].Posts {
+ // fmt.Println(p.ID)
+ // }
+
+ // we iterate through every user within our users array and
+ // print out the user Type, their name, and their facebook url
+ // as just an example
+ // for i := 0; i < len(users.Users); i++ {
+ // fmt.Println("User Type: " + users.Users[i].Type)
+ // fmt.Println("User Age: " + strconv.Itoa(users.Users[i].Age))
+ // fmt.Println("User Name: " + users.Users[i].Name)
+ // fmt.Println("Facebook Url: " + users.Users[i].Social.Facebook)
+ // }
}
+
+// func zipreader(src string) ([]string, error) {
+
+// // Open a zip archive for reading.
+// r, err := zip.OpenReader("testdata/readme.zip")
+// if err != nil {
+// log.Fatal(err)
+// }
+// defer r.Close()
+
+// // Iterate through the files in the archive,
+// // printing some of their contents.
+// for _, f := range r.File {
+// fmt.Printf("Contents of %s:\n", f.Name)
+// rc, err := f.Open()
+// if err != nil {
+// log.Fatal(err)
+// }
+// _, err = io.CopyN(os.Stdout, rc, 68)
+// if err != nil {
+// log.Fatal(err)
+// }
+// rc.Close()
+// fmt.Println()
+// }
+
+// return
+// }
diff --git a/templates/user/import.tmpl b/templates/user/import.tmpl
index d5db26f..70cda12 100644
--- a/templates/user/import.tmpl
+++ b/templates/user/import.tmpl
@@ -1,28 +1,29 @@
{{define "import"}}
{{template "header" .}}
<div class="snug content-container">
<h2 id="posts-header">Import</h2>
- <p>You may import your data from another instance at any time here.</p>
+ <p>You may import your data from another instance here.</p>
<table class="classy export">
<tr>
<th style="width: 40%">Export</th>
<th colspan="2">Format</th>
</tr>
<tr>
<th>Posts</th>
<td><p class="text-cta"><a href="">CSV</a></p></td>
<td><p class="text-cta"><a href="">TXT</a></p></td>
</tr>
<tr>
<th>User + Blogs + Posts</th>
+ <!-- TODO: Add inputs like: <td><input type="file" accept="text/JSON">JSON<input/></td> -->
<td><p class="text-cta"><a href="">JSON</a></p></td>
<td><p class="text-cta"><a href="">Prettified</a></p></td>
</tr>
</table>
</div>
{{template "footer" .}}
{{end}}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, May 16, 2:51 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3240162
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment