From 0716bfdecff069d7337b2c4ab46368c28912d218 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 25 Jul 2014 14:07:17 -0700 Subject: [PATCH] twitter: revert 98a73d966d; it changed its imported root structure I failed to catch that in review. Change-Id: Ie88298a2f34595b27c6f98af6f31b61a29ebac1b --- pkg/importer/twitter/twitter.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/importer/twitter/twitter.go b/pkg/importer/twitter/twitter.go index 10b616597..4ccbe9fca 100644 --- a/pkg/importer/twitter/twitter.go +++ b/pkg/importer/twitter/twitter.go @@ -187,12 +187,6 @@ func (im *imp) Run(ctx *importer.RunContext) error { }, } - rootNode := r.RootNode() - if rootNode.Attr(nodeattr.Title) == "" { - screenName := acctNode.Attr(importer.AcctAttrUserName) - rootNode.SetAttr(nodeattr.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.") @@ -253,7 +247,11 @@ func (r *run) importTweets(userID string) error { maxId := "" continueRequests := true - tweetsNode := r.RootNode() + tweetsNode, err := r.getTopLevelNode("tweets", "Tweets") + if err != nil { + return err + } + numTweets := 0 sawTweet := map[string]bool{} @@ -355,7 +353,10 @@ 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 := r.RootNode() + tweetsNode, err := r.getTopLevelNode("tweets", "Tweets") + if err != nil { + return err + } var ( gate = syncutil.NewGate(tweetsAtOnce) @@ -382,7 +383,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 } @@ -498,6 +499,17 @@ 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 {