From 98a73d966dbafcb08f50496863142a4db406c7a9 Mon Sep 17 00:00:00 2001
From: "Piotr S. Staszewski"
Date: Tue, 1 Jul 2014 20:41:53 +0200
Subject: [PATCH] twitter importer: meaningful names for permanodes
Make meaningful titles for created permanodes, simplified.
Change-Id: If0575b5c0ffec037feb8ce74e46f66556c582372
---
pkg/importer/twitter/twitter.go | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/pkg/importer/twitter/twitter.go b/pkg/importer/twitter/twitter.go
index 5f0727be9..57ced51f6 100644
--- a/pkg/importer/twitter/twitter.go
+++ b/pkg/importer/twitter/twitter.go
@@ -191,6 +191,12 @@ func (im *imp) Run(ctx *importer.RunContext) error {
},
}
+ rootNode := r.RootNode()
+ if rootNode.Attr("title") == "" {
+ screenName := acctNode.Attr(importer.AcctAttrUserName)
+ rootNode.SetAttr("title", fmt.Sprintf("%s's Tweets", screenName))
+ }
+
userID := acctNode.Attr(importer.AcctAttrUserID)
if userID == "" {
return errors.New("UserID hasn't been set by account setup.")
@@ -251,11 +257,7 @@ func (r *run) importTweets(userID string) error {
maxId := ""
continueRequests := true
- tweetsNode, err := r.getTopLevelNode("tweets", "Tweets")
- if err != nil {
- return err
- }
-
+ tweetsNode := r.RootNode()
numTweets := 0
sawTweet := map[string]bool{}
@@ -346,10 +348,7 @@ func tweetsFromZipFile(zf *zip.File) (tweets []*zipTweetItem, err error) {
func (r *run) importTweetsFromZip(userID string, zr *zip.Reader) error {
log.Printf("Processing zip file with %d files", len(zr.File))
- tweetsNode, err := r.getTopLevelNode("tweets", "Tweets")
- if err != nil {
- return err
- }
+ tweetsNode := r.RootNode()
var (
gate = syncutil.NewGate(tweetsAtOnce)
@@ -376,7 +375,7 @@ func (r *run) importTweetsFromZip(userID string, zr *zip.Reader) error {
})
}
}
- err = grp.Err()
+ err := grp.Err()
log.Printf("zip import of tweets: %d total, err = %v", total, err)
return err
}
@@ -492,17 +491,6 @@ func (r *run) importTweet(parent *importer.Object, tweet tweetItem, viaAPI bool)
return !changes, err
}
-func (r *run) getTopLevelNode(path string, title string) (*importer.Object, error) {
- tweets, err := r.RootNode().ChildPathObject(path)
- if err != nil {
- return nil, err
- }
- if err := tweets.SetAttr("title", title); err != nil {
- return nil, err
- }
- return tweets, nil
-}
-
// TODO(mpl): move to an api.go when we it gets bigger.
type userInfo struct {
@@ -618,6 +606,7 @@ func (im *imp) ServeCallback(w http.ResponseWriter, r *http.Request, ctx *import
importer.AcctAttrUserID, u.ID,
importer.AcctAttrName, u.Name,
importer.AcctAttrUserName, u.ScreenName,
+ "title", fmt.Sprintf("%s's Twitter Account", u.ScreenName),
); err != nil {
httputil.ServeError(w, r, fmt.Errorf("Error setting attribute: %v", err))
return