Skip to content

Instantly share code, notes, and snippets.

@lancew
Created October 3, 2018 08:33
Show Gist options
  • Save lancew/35afaad22c4a2d12385498590de33183 to your computer and use it in GitHub Desktop.
Save lancew/35afaad22c4a2d12385498590de33183 to your computer and use it in GitHub Desktop.
Perkeep in progress twitter change
[lancew@spectre perkeep.org]$ git diff
diff --git a/pkg/importer/twitter/twitter.go b/pkg/importer/twitter/twitter.go
index b1749504..905fc504 100644
--- a/pkg/importer/twitter/twitter.go
+++ b/pkg/importer/twitter/twitter.go
@@ -44,6 +44,7 @@ import (
"perkeep.org/pkg/schema/nodeattr"
"github.com/garyburd/go-oauth/oauth"
+ "github.com/gernest/mention"
"go4.org/ctxutil"
"go4.org/syncutil"
@@ -163,6 +164,7 @@ func (im *imp) AccountSetupHTML(host *importer.Host) string {
<li>Description: Does not matter. (imports twitter data into camlistore).</li>
<li>Website: <b>%s</b></li>
<li>Callback URL: <b>%s</b></li>
+ <li>Tags (comma seperated): <b>%s</b></li>
</ul>
<!-- TODO(mpl): use CSS to style it to 80 chars wide instead of doing it in source -->
<p>
@@ -584,7 +586,9 @@ func (r *run) importTweet(parent *importer.Object, tweet tweetItem, viaAPI bool)
nodeattr.StartDate, schema.RFC3339FromTime(createdTime),
nodeattr.Content, tweet.Text(),
nodeattr.URL, url,
+ "tag", "twitter",
}
+
if lat, long, ok := tweet.LatLong(); ok {
attrs = append(attrs,
nodeattr.Latitude, fmt.Sprint(lat),
@@ -637,10 +641,20 @@ func (r *run) importTweet(parent *importer.Object, tweet tweetItem, viaAPI bool)
}
}
+ tags := mention.GetTagsAsUniqueStrings('#', tweet.Text())
+ for i, v := range tags {
+ tags[i] = strings.ToLower(v)
+ }
+ tags = append(tags, "twitter")
+
changes, err := tweetNode.SetAttrs2(attrs...)
if err == nil && changes {
log.Printf("twitter: imported tweet %s", url)
}
+
+ if err := tweetNode.SetAttrValues("tag", tags); err != nil {
+ return false, err
+ }
return !changes, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment