domain_import_disqus.go: update disqus export spec
This commit is contained in:
parent
815628c5ee
commit
20b6660fa9
@ -18,9 +18,9 @@ type disqusThread struct {
|
|||||||
|
|
||||||
type disqusAuthor struct {
|
type disqusAuthor struct {
|
||||||
XMLName xml.Name `xml:"author"`
|
XMLName xml.Name `xml:"author"`
|
||||||
IsAnonymous bool `xml:"isAnonymous"`
|
|
||||||
Name string `xml:"name"`
|
Name string `xml:"name"`
|
||||||
Email string `xml:"email"`
|
IsAnonymous bool `xml:"isAnonymous"`
|
||||||
|
Username string `xml:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type disqusThreadId struct {
|
type disqusThreadId struct {
|
||||||
@ -43,7 +43,6 @@ type disqusPost struct {
|
|||||||
Id string `xml:"http://disqus.com/disqus-internals id,attr"`
|
Id string `xml:"http://disqus.com/disqus-internals id,attr"`
|
||||||
ThreadId disqusThreadId `xml:"thread"`
|
ThreadId disqusThreadId `xml:"thread"`
|
||||||
ParentId disqusParentId `xml:"parent"`
|
ParentId disqusParentId `xml:"parent"`
|
||||||
PostId disqusPostId `xml:"post"`
|
|
||||||
Message string `xml:"message"`
|
Message string `xml:"message"`
|
||||||
CreationDate time.Time `xml:"createdAt"`
|
CreationDate time.Time `xml:"createdAt"`
|
||||||
IsDeleted bool `xml:"isDeleted"`
|
IsDeleted bool `xml:"isDeleted"`
|
||||||
@ -98,24 +97,26 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
|
|
||||||
// Map Disqus emails to commenterHex (if not available, create a new one
|
// Map Disqus emails to commenterHex (if not available, create a new one
|
||||||
// with a random password that can be reset later).
|
// with a random password that can be reset later).
|
||||||
commenterHex := make(map[string]string)
|
commenterHex := map[string]string{}
|
||||||
for _, post := range x.Posts {
|
for _, post := range x.Posts {
|
||||||
if post.IsDeleted || post.IsSpam {
|
if post.IsDeleted || post.IsSpam {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := commenterHex[post.Author.Email]; ok {
|
email := post.Author.Username + "@disqus.com"
|
||||||
|
|
||||||
|
if _, ok := commenterHex[email]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := commenterGetByEmail("commento", post.Author.Email)
|
c, err := commenterGetByEmail("commento", email)
|
||||||
if err != nil && err != errorNoSuchCommenter {
|
if err != nil && err != errorNoSuchCommenter {
|
||||||
logger.Errorf("cannot get commenter by email: %v", err)
|
logger.Errorf("cannot get commenter by email: %v", err)
|
||||||
return 0, errorInternal
|
return 0, errorInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
commenterHex[post.Author.Email] = c.CommenterHex
|
commenterHex[email] = c.CommenterHex
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
return 0, errorInternal
|
return 0, errorInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
commenterHex[post.Author.Email], err = commenterNew(post.Author.Email, post.Author.Name, "undefined", "undefined", "commento", randomPassword)
|
commenterHex[email], err = commenterNew(email, post.Author.Name, "undefined", "undefined", "commento", randomPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -134,12 +135,17 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
// For each Disqus post, create a Commento comment. Attempt to convert the
|
// For each Disqus post, create a Commento comment. Attempt to convert the
|
||||||
// HTML to markdown.
|
// HTML to markdown.
|
||||||
numImported := 0
|
numImported := 0
|
||||||
disqusIdMap := make(map[string]string)
|
disqusIdMap := map[string]string{}
|
||||||
for _, post := range x.Posts {
|
for _, post := range x.Posts {
|
||||||
if post.IsDeleted || post.IsSpam {
|
if post.IsDeleted || post.IsSpam {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cHex := "anonymous"
|
||||||
|
if !post.Author.IsAnonymous {
|
||||||
|
cHex = commenterHex[post.Author.Username+"@disqus.com"]
|
||||||
|
}
|
||||||
|
|
||||||
parentHex := "root"
|
parentHex := "root"
|
||||||
if val, ok := disqusIdMap[post.ParentId.Id]; ok {
|
if val, ok := disqusIdMap[post.ParentId.Id]; ok {
|
||||||
parentHex = val
|
parentHex = val
|
||||||
@ -148,7 +154,7 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
// TODO: restrict the list of tags to just the basics: <a>, <b>, <i>, <code>
|
// TODO: restrict the list of tags to just the basics: <a>, <b>, <i>, <code>
|
||||||
// Especially remove <img> (convert it to <a>).
|
// Especially remove <img> (convert it to <a>).
|
||||||
commentHex, err := commentNew(
|
commentHex, err := commentNew(
|
||||||
commenterHex[post.Author.Email],
|
cHex,
|
||||||
domain,
|
domain,
|
||||||
pathStrip(threads[post.ThreadId.Id].URL),
|
pathStrip(threads[post.ThreadId.Id].URL),
|
||||||
parentHex,
|
parentHex,
|
||||||
@ -159,7 +165,7 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
return numImported, err
|
return numImported, err
|
||||||
}
|
}
|
||||||
|
|
||||||
disqusIdMap[post.PostId.Id] = commentHex
|
disqusIdMap[post.Id] = commentHex
|
||||||
numImported += 1
|
numImported += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user