twitter: revert 98a73d966d; it changed its imported root structure

I failed to catch that in review.

Change-Id: Ie88298a2f34595b27c6f98af6f31b61a29ebac1b
This commit is contained in:
Brad Fitzpatrick 2014-07-25 14:07:17 -07:00
parent 8af06fa3ff
commit 0716bfdecf
1 changed files with 21 additions and 9 deletions

View File

@ -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) userID := acctNode.Attr(importer.AcctAttrUserID)
if userID == "" { if userID == "" {
return errors.New("UserID hasn't been set by account setup.") return errors.New("UserID hasn't been set by account setup.")
@ -253,7 +247,11 @@ func (r *run) importTweets(userID string) error {
maxId := "" maxId := ""
continueRequests := true continueRequests := true
tweetsNode := r.RootNode() tweetsNode, err := r.getTopLevelNode("tweets", "Tweets")
if err != nil {
return err
}
numTweets := 0 numTweets := 0
sawTweet := map[string]bool{} 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 { func (r *run) importTweetsFromZip(userID string, zr *zip.Reader) error {
log.Printf("Processing zip file with %d files", len(zr.File)) 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 ( var (
gate = syncutil.NewGate(tweetsAtOnce) 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) log.Printf("zip import of tweets: %d total, err = %v", total, err)
return err return err
} }
@ -498,6 +499,17 @@ func (r *run) importTweet(parent *importer.Object, tweet tweetItem, viaAPI bool)
return !changes, err 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. // TODO(mpl): move to an api.go when we it gets bigger.
type userInfo struct { type userInfo struct {