| 206 | var forceFullImport, _ = strconv.ParseBool(os.Getenv("CAMLI_TWITTER_FULL_IMPORT")) |
| 207 | |
| 208 | func (im *imp) Run(ctx *importer.RunContext) error { |
| 209 | clientId, secret, err := ctx.Credentials() |
| 210 | if err != nil { |
| 211 | return fmt.Errorf("no API credentials: %v", err) |
| 212 | } |
| 213 | acctNode := ctx.AccountNode() |
| 214 | accessToken := acctNode.Attr(importer.AcctAttrAccessToken) |
| 215 | accessSecret := acctNode.Attr(importer.AcctAttrAccessTokenSecret) |
| 216 | if accessToken == "" || accessSecret == "" { |
| 217 | return errors.New("access credentials not found") |
| 218 | } |
| 219 | r := &run{ |
| 220 | RunContext: ctx, |
| 221 | im: im, |
| 222 | incremental: !forceFullImport && acctNode.Attr(importer.AcctAttrCompletedVersion) == runCompleteVersion, |
| 223 | |
| 224 | oauthClient: &oauth.Client{ |
| 225 | TemporaryCredentialRequestURI: temporaryCredentialRequestURL, |
| 226 | ResourceOwnerAuthorizationURI: resourceOwnerAuthorizationURL, |
| 227 | TokenRequestURI: tokenRequestURL, |
| 228 | Credentials: oauth.Credentials{ |
| 229 | Token: clientId, |
| 230 | Secret: secret, |
| 231 | }, |
| 232 | }, |
| 233 | accessCreds: &oauth.Credentials{ |
| 234 | Token: accessToken, |
| 235 | Secret: accessSecret, |
| 236 | }, |
| 237 | } |
| 238 | |
| 239 | userID := acctNode.Attr(importer.AcctAttrUserID) |
| 240 | if userID == "" { |
| 241 | return errors.New("userID hasn't been set by account setup") |
| 242 | } |
| 243 | |
| 244 | skipAPITweets, _ := strconv.ParseBool(os.Getenv("CAMLI_TWITTER_SKIP_API_IMPORT")) |
| 245 | if !skipAPITweets { |
| 246 | if err := r.importTweets(userID, userTimeLineAPIPath); err != nil { |
| 247 | return err |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | acctNode, err = ctx.Host.ObjectFromRef(acctNode.PermanodeRef()) |
| 252 | if err != nil { |
| 253 | return fmt.Errorf("error reloading account node: %v", err) |
| 254 | } |
| 255 | importLikes, err := strconv.ParseBool(acctNode.Attr(acctAttrImportLikes)) |
| 256 | if err == nil && importLikes { |
| 257 | if err := r.importTweets(userID, userLikesAPIPath); err != nil { |
| 258 | return err |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | zipRef := acctNode.Attr(acctAttrTweetZip) |
| 263 | zipDoneVal := zipRef + ":" + runCompleteVersion |
| 264 | if zipRef != "" && !(r.incremental && acctNode.Attr(acctAttrZipDoneVersion) == zipDoneVal) { |
| 265 | zipbr, ok := blob.Parse(zipRef) |