Esempio n. 1
0
// updatePrimaryPhoto uses the camliContent of photoNode to set the
// camliContentImage of any album for which photoNode is the primary photo.
func (r *run) updatePrimaryPhoto(photoNode *importer.Object) error {
	photoId := photoNode.Attr(attrFlickrId)
	for album, photo := range r.primaryPhoto {
		if photoId != photo {
			continue
		}
		setsNode, err := r.getTopLevelNode("sets", "Sets")
		if err != nil {
			return fmt.Errorf("could not set %v as primary photo of %v, no root sets: %v", photoId, album, err)
		}
		setNode, err := setsNode.ChildPathObject(album)
		if err != nil {
			return fmt.Errorf("could not set %v as primary photo of %v, no album: %v", photoId, album, err)
		}
		fileRef := photoNode.Attr(nodeattr.CamliContent)
		if fileRef == "" {
			return fmt.Errorf("could not set %v as primary photo of %v: fileRef of photo is unknown", photoId, album)
		}
		if err := setNode.SetAttr(nodeattr.CamliContentImage, fileRef); err != nil {
			return fmt.Errorf("could not set %v as primary photo of %v: %v", photoId, album, err)
		}
		delete(r.primaryPhoto, album)
	}
	return nil
}
Esempio n. 2
0
func (im imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil || !ok {
		return ""
	}
	return acct.Attr(importer.AcctAttrUserName)
}
Esempio n. 3
0
func (*imp) IsAccountReady(acct *importer.Object) (ready bool, err error) {
	// This method tells the importer framework whether this account
	// permanode (accessed via the importer.Object) is ready to start
	// an import.  Here you would typically check whether you have the
	// right metadata/tokens on the account.
	return acct.Attr(acctAttrToken) != "" && acct.Attr(acctAttrUsername) != "", nil
}
Esempio n. 4
0
func (im *imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil {
		return "Not configured; error = " + err.Error()
	}
	if !ok {
		return "Not configured"
	}
	return fmt.Sprintf("feed %s", acct.Attr(acctAttrFeedURL))
}
Esempio n. 5
0
func (im imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil {
		return "Not configured; error = " + err.Error()
	}
	if !ok {
		return "Not configured"
	}
	return fmt.Sprintf("Pinboard account for %s", extractUsername(acct.Attr(attrAuthToken)))
}
Esempio n. 6
0
func (im *imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil {
		return "Not configured; error = " + err.Error()
	}
	if !ok {
		return "Not configured"
	}
	s := fmt.Sprintf("@%s (%s), twitter id %s",
		acct.Attr(importer.AcctAttrUserName),
		acct.Attr(importer.AcctAttrName),
		acct.Attr(importer.AcctAttrUserID),
	)
	if acct.Attr(acctAttrTweetZip) != "" {
		s += " + zip file"
	}
	return s
}
Esempio n. 7
0
func (r *run) importPhotos(placeNode *importer.Object) error {
	photosNode, err := placeNode.ChildPathObject("photos")
	if err != nil {
		return err
	}

	if err := photosNode.SetAttrs(
		"title", "Photos of "+placeNode.Attr("title"),
		"camliDefVis", "hide"); err != nil {
		return err
	}

	resp := photosList{}
	if err := r.im.doAPI(r.Context, r.token(), &resp, "venues/"+placeNode.Attr("foursquareId")+"/photos", "limit", "10"); err != nil {
		return err
	}

	var need []*photoItem
	for _, photo := range resp.Response.Photos.Items {
		attr := "camliPath:" + photo.Id + filepath.Ext(photo.Suffix)
		if photosNode.Attr(attr) == "" {
			need = append(need, photo)
		}
	}

	if len(need) > 0 {
		log.Printf("foursquare: importing %d photos for venue %s", len(need), placeNode.Attr("title"))
		for _, photo := range need {
			attr := "camliPath:" + photo.Id + filepath.Ext(photo.Suffix)
			url := photo.Prefix + "original" + photo.Suffix
			log.Printf("foursquare: importing photo for venue %s: %s", placeNode.Attr("title"), url)
			ref := r.urlFileRef(url, "")
			if ref == "" {
				log.Printf("Error slurping photo: %s", url)
				continue
			}
			if err := photosNode.SetAttr(attr, ref); err != nil {
				log.Printf("Error adding venue photo: %#v", err)
			}
		}
	}

	return nil
}
Esempio n. 8
0
func (r *run) importPhotos(placeNode *importer.Object) error {
	photosNode, err := placeNode.ChildPathObject("photos")
	if err != nil {
		return err
	}

	photosNode.SetAttrs(
		"title", "Photos of "+placeNode.Attr("title"),
		"camliDefVis", "hide")

	resp := photosList{}
	if err := r.im.doAPI(r.Context, r.token(), &resp, "venues/"+placeNode.Attr("foursquareId")+"/photos", "limit", "10"); err != nil {
		return err
	}

	itemcount := len(resp.Response.Photos.Items)
	log.Printf("Importing %d photos for venue %s", itemcount, placeNode.Attr("title"))

	for _, photo := range resp.Response.Photos.Items {
		attr := "camliPath:" + photo.Id + filepath.Ext(photo.Suffix)
		if photosNode.Attr(attr) != "" {
			log.Printf("Skipping photo, we already have it")
			// Assume we have this photo already and don't need to refetch.
			continue
		}
		url := photo.Prefix + "original" + photo.Suffix
		ref := r.urlFileRef(url, "")
		if ref == "" {
			log.Printf("Error slurping photo: %s", url)
			continue
		}
		err = photosNode.SetAttr(attr, ref)
		if err != nil {
			log.Printf("Error adding venue photo: %#v", err)
		}
	}

	return nil
}
Esempio n. 9
0
func (extendedOAuth2) IsAccountReady(acctNode *importer.Object) (ok bool, err error) {
	if acctNode.Attr(importer.AcctAttrUserID) != "" && acctNode.Attr(acctAttrOAuthToken) != "" {
		return true, nil
	}
	return false, nil
}
Esempio n. 10
0
func (im *imp) IsAccountReady(acctNode *importer.Object) (ok bool, err error) {
	if acctNode.Attr(acctAttrFeedURL) != "" {
		return true, nil
	}
	return false, nil
}
Esempio n. 11
0
func (im *imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil {
		return "Not configured; error = " + err.Error()
	}
	if !ok {
		return "Not configured"
	}
	if acct.Attr(acctAttrUserFirst) == "" && acct.Attr(acctAttrUserLast) == "" {
		return fmt.Sprintf("@%s", acct.Attr(acctAttrScreenName))
	}
	return fmt.Sprintf("@%s (%s %s)", acct.Attr(acctAttrScreenName),
		acct.Attr(acctAttrUserFirst), acct.Attr(acctAttrUserLast))
}
Esempio n. 12
0
func (im *imp) IsAccountReady(acctNode *importer.Object) (ok bool, err error) {
	if acctNode.Attr(acctAttrUserID) != "" && acctNode.Attr(acctAttrAccessToken) != "" {
		return true, nil
	}
	return false, nil
}
Esempio n. 13
0
func (r *run) importPhotos(placeNode *importer.Object, checkinWasDup bool) error {
	photosNode, err := placeNode.ChildPathObject("photos")
	if err != nil {
		return err
	}

	if err := photosNode.SetAttrs(
		nodeattr.Title, "Photos of "+placeNode.Attr("title"),
		nodeattr.DefaultVisibility, "hide"); err != nil {
		return err
	}

	nHave := 0
	photosNode.ForeachAttr(func(key, value string) {
		if strings.HasPrefix(key, "camliPath:") {
			nHave++
		}
	})
	nWant := photosRequestLimit
	if checkinWasDup {
		nWant = 1
	}
	if nHave >= nWant {
		return nil
	}

	resp := photosList{}
	if err := r.im.doAPI(r.Context, r.token(), &resp,
		"venues/"+placeNode.Attr(attrFoursquareId)+"/photos",
		"limit", strconv.Itoa(nWant)); err != nil {
		return err
	}

	var need []*photoItem
	for _, photo := range resp.Response.Photos.Items {
		attr := "camliPath:" + photo.Id + filepath.Ext(photo.Suffix)
		if photosNode.Attr(attr) == "" {
			need = append(need, photo)
		}
	}

	if len(need) > 0 {
		venueTitle := placeNode.Attr(nodeattr.Title)
		log.Printf("foursquare: importing %d photos for venue %s", len(need), venueTitle)
		for _, photo := range need {
			attr := "camliPath:" + photo.Id + filepath.Ext(photo.Suffix)
			if photosNode.Attr(attr) != "" {
				continue
			}
			url := photo.Prefix + "original" + photo.Suffix
			log.Printf("foursquare: importing photo for venue %s: %s", venueTitle, url)
			ref := r.urlFileRef(url, "")
			if ref == "" {
				r.errorf("Error slurping photo: %s", url)
				continue
			}
			if err := photosNode.SetAttr(attr, ref); err != nil {
				r.errorf("Error adding venue photo: %#v", err)
			}
		}
	}

	return nil
}
Esempio n. 14
0
func (imp) IsAccountReady(acctNode *importer.Object) (ok bool, err error) {
	return acctNode.Attr(importer.AcctAttrUserName) != "" && acctNode.Attr(importer.AcctAttrAccessToken) != "", nil
}
Esempio n. 15
0
func (im imp) SummarizeAccount(acct *importer.Object) string {
	ok, err := im.IsAccountReady(acct)
	if err != nil || !ok {
		return ""
	}
	if acct.Attr(importer.AcctAttrGivenName) == "" && acct.Attr(importer.AcctAttrFamilyName) == "" {
		return fmt.Sprintf("userid %s", acct.Attr(importer.AcctAttrUserID))
	}
	return fmt.Sprintf("userid %s (%s %s)",
		acct.Attr(importer.AcctAttrUserID),
		acct.Attr(importer.AcctAttrGivenName),
		acct.Attr(importer.AcctAttrFamilyName))
}
Esempio n. 16
0
func (*imp) SummarizeAccount(acct *importer.Object) string {
	// This method is run by the importer framework if the account is
	// ready (see IsAccountReady) and summarizes the account in
	// the list of accounts on the importer page.
	return acct.Attr(acctAttrUsername)
}
Esempio n. 17
0
func (imp) IsAccountReady(acct *importer.Object) (ready bool, err error) {
	ready = acct.Attr(attrAuthToken) != ""
	return ready, nil
}