twigger

package module
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 21 Imported by: 3

README

Twigger

  • Twigger is helper library written in Go that aims to make common Twitter API calls easier.
  • Twigger is based on Twitter API library anaconda.
  • Twigger also provides easy to use CLI commands for some most common Twitter API calls.
  • Neither Twigger API nor Twigger CLI commands are exhaustive for now.

Example Usage of Twigger API

creds, err := twigger.LoadJSONCredentials("test_resources/login.json")

homeDir, _ := os.UserHomeDir()
homeDir = homeDir + "/"

logFile, _ := os.OpenFile(homeDir + "out.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer logFile.Close()

conn,  err := twigger.NewConnection(creds, logFile, os.Stdout, os.Stderr)
if err != nil{
    log.Fatalln("Cannot create a new connection!")
}

tweets, _ := conn.GetAllRecentTweetsFromScreenName("BBCWorld")
tweets.Save(homeDir + "bbc_tweets.json")

favs, _   := conn.GetAllRecentFavoritesFromScreenName("philosophybites")
favs.Save(homeDir + "philosophybites_favs.json")

friends, _ := conn.GetAllFriendsFromScreenName("twitterVideo")
friends.Save(homeDir + "twitter_video_friends.json")
followers, _ := conn.GetAllFollowersFromScreenName("randomartdaily")
followers.Save(homeDir + "randomartdaily_followers.json")

followers, _ = conn.GetNFollowersFromScreenName(2000, "BBCEarth")
followers.Save(homeDir + "bbcearth_2000_followers.json")

popTweets, _ := conn.GetPopularTweetsByQuery("Apple M1")
popTweets.Save(homeDir + "apple_m1_pop_tweets.json")

picturePaths := []string{
    "test_resources/antalya.jpg",
    "test_resources/eskisehir.jpg",
    "test_resources/stars.jpg",
    "test_resources/ny.jpg",
    "test_resources/providence.jpg",
}

conn.PublishCollageTweet(picturePaths,"This is a test tweet and will be deleted soon.")
conn.PublishVideoTweet("test_resources/video.mp4", "this is a video test tweet and will be deleted in minutes.")

Installing Twigger CLI Commands

  1. go get github.com/gusanmaz/twigger

  2. cd $GOPATH/src/github.com/gusanmaz/twigger

  3. find ./cmd/twigger* -type d | xargs go install

Twigger CLI Usage Examples

  • Getting all recent favorites of a user

twigger-user-favs -credentials creds.json -screenname nixcraft -output nixcraft_favs.json

  • Getting all recent tweets of a user

twigger-user-tweets -credentials creds.json -screenname nixcraft -output nixcraft_tweets.json

  • Getting all friends of a user

twigger-user-friends -credentials creds.json -screenname nixcraft -output nixcraft_friends.json

  • Getting 2000 followers of a user

twigger-user-tweets -credentials creds.json -screenname nixcraft -n 2000 -output nixcraft_followers.json

Author

Güvenç Usanmaz

License

MIT License

Documentation

Index

Constants

View Source
const (
	RelationFriend   = "friend"
	RelationFollower = "follower"
)
View Source
const (
	MediaText    = "text" // No use for now
	MediaPicture = "picture"
	MediaCollage = "collage"
	MediaVideo   = "video"
)
View Source
const (
	EntityTweet        = "tweet"
	EntityFavorite     = "favorite"
	EntityRetweet      = "retweet"
	EntityHomeTimeLine = "home-timeline-tweet"
	EntityMention      = "mention-tweet"
	EntityAPILimit     = 5000 // It is actually 3200 and this constant is set to 5000 to be on the safe side!
)
View Source
const (
	// These two limits are actually 3200!
	LimitFavs            = 4000
	LimitTweets          = 4000
	LimitTimelineTweeets = 4000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Client      *anaconda.TwitterApi
	Credentials Credentials

	InfoLog *log.Logger
	ErrLog  *log.Logger

	User         *anaconda.User
	CreationTime int64
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(c Credentials, logFile, logOutFile, logErrFile *os.File) (*Connection, error)

func (*Connection) CheckUserValueIntegrity

func (c *Connection) CheckUserValueIntegrity(v url.Values) bool

func (*Connection) DeleteTweetFromID

func (c *Connection) DeleteTweetFromID(id string) (Tweet, error)

func (*Connection) FillMissingUserValues

func (c *Connection) FillMissingUserValues(v url.Values) error

func (*Connection) GetAllFollowersFromID

func (c *Connection) GetAllFollowersFromID(userID string) (Users, error)

func (*Connection) GetAllFollowersFromScreenName

func (c *Connection) GetAllFollowersFromScreenName(screenName string) (Users, error)

func (*Connection) GetAllFriendsFromID

func (c *Connection) GetAllFriendsFromID(userID string) (Users, error)

func (*Connection) GetAllFriendsFromScreenName

func (c *Connection) GetAllFriendsFromScreenName(screenName string) (Users, error)

func (*Connection) GetAllRecentFavoritesFromScreenName

func (c *Connection) GetAllRecentFavoritesFromScreenName(screenName string) (Tweets, error)

func (*Connection) GetAllRecentMentions

func (c *Connection) GetAllRecentMentions() (Tweets, error)

func (*Connection) GetAllRecentMentionsSince

func (c *Connection) GetAllRecentMentionsSince(sinceID int64) (Tweets, error)

func (*Connection) GetAllRecentNHomeTimelineTweets

func (c *Connection) GetAllRecentNHomeTimelineTweets() (Tweets, error)

func (*Connection) GetAllRecentTweetsFromScreenName

func (c *Connection) GetAllRecentTweetsFromScreenName(screenName string) (Tweets, error)

func (*Connection) GetIDFromScreenName

func (c *Connection) GetIDFromScreenName(screenName string) (int64, error)

func (*Connection) GetMixedTweetsByQuery

func (c *Connection) GetMixedTweetsByQuery(query string) (Tweets, error)

func (*Connection) GetNFollowersFromID

func (c *Connection) GetNFollowersFromID(n int, userID string) (Users, error)

func (*Connection) GetNFollowersFromScreenName

func (c *Connection) GetNFollowersFromScreenName(n int, screenName string) (Users, error)

func (*Connection) GetNFriendsFromID

func (c *Connection) GetNFriendsFromID(n int, userID string) (Users, error)

func (*Connection) GetNFriendsFromScreenName

func (c *Connection) GetNFriendsFromScreenName(n int, screenName string) (Users, error)

func (*Connection) GetPopularTweetsByQuery

func (c *Connection) GetPopularTweetsByQuery(query string) (Tweets, error)

func (*Connection) GetRecentNFavoritesFromScreenName

func (c *Connection) GetRecentNFavoritesFromScreenName(screenName string, n int) (Tweets, error)

func (*Connection) GetRecentNHomeTimelineTweets

func (c *Connection) GetRecentNHomeTimelineTweets(n int) (Tweets, error)

func (*Connection) GetRecentNMentions

func (c *Connection) GetRecentNMentions(n int) (Tweets, error)

func (*Connection) GetRecentNMentionsSince

func (c *Connection) GetRecentNMentionsSince(n int, sinceID int64) (Tweets, error)

func (*Connection) GetRecentNTweetsFromScreenName

func (c *Connection) GetRecentNTweetsFromScreenName(screenName string, n int) (Tweets, error)

func (*Connection) GetRecentTweetsByQuery

func (c *Connection) GetRecentTweetsByQuery(query string) (Tweets, error)

func (*Connection) GetScreenNameFromID

func (c *Connection) GetScreenNameFromID(id int64) (string, error)

func (*Connection) GetSingleTweetFromID

func (c *Connection) GetSingleTweetFromID(id int64) (Tweet, error)

func (*Connection) GetTopUsersFromQuery

func (c *Connection) GetTopUsersFromQuery(query string) (Users, error)

func (*Connection) GetXTweetsByQuery

func (c *Connection) GetXTweetsByQuery(query string, v url.Values) (Tweets, error)

func (*Connection) PublishCollageTweet

func (c *Connection) PublishCollageTweet(filePaths []string, text string) (int64, error)

func (*Connection) PublishCollageTweetAsReply

func (c *Connection) PublishCollageTweetAsReply(filePaths []string, text string, replyTweetID int64) (int64, error)

func (*Connection) PublishPictureTweet

func (c *Connection) PublishPictureTweet(filepath string, text string) (int64, error)

func (*Connection) PublishPictureTweetAsReply

func (c *Connection) PublishPictureTweetAsReply(filepath string, text string, replyTweetID int64) (int64, error)

func (*Connection) PublishTextTweet

func (c *Connection) PublishTextTweet(text string) (int64, error)

func (*Connection) PublishTextTweetAsReply

func (c *Connection) PublishTextTweetAsReply(text string, replyTweetID int64) (int64, error)

func (*Connection) PublishVideoTweet

func (c *Connection) PublishVideoTweet(filepath string, text string) (int64, error)

func (*Connection) PublishVideoTweetAsReply

func (c *Connection) PublishVideoTweetAsReply(filepath string, text string, replyTweetID int64) (int64, error)

func (*Connection) Reconnect added in v0.4.0

func (c *Connection) Reconnect()

func (*Connection) UploadImage

func (c *Connection) UploadImage(filepath string) (int64, error)

func (*Connection) UploadVideo

func (c *Connection) UploadVideo(filepath string) (int64, error)

type Credentials

type Credentials struct {
	APIKey       string `json:"APIKey" yaml:"APIKey"`
	APISecret    string `json:"APISecret" yaml:"APISecret"`
	AccessToken  string `json:"accessToken" yaml:"accessToken"`
	AccessSecret string `json:"accessSecret" yaml:"accessSecret"`
	BearerToken  string `json:"bearerToken" yaml:"bearerToken"`
}

func LoadCredentials

func LoadCredentials(filepath string) (Credentials, error)

func LoadJSONCredentials

func LoadJSONCredentials(filepath string) (Credentials, error)

func LoadYAMLCredentials

func LoadYAMLCredentials(filepath string) (Credentials, error)

type EntityFunc

type EntityFunc func(values url.Values) ([]anaconda.Tweet, error)

type RelationFunc

type RelationFunc func(v url.Values) (c anaconda.UserCursor, err error)

type RelationInfo

type RelationInfo struct {
	Func RelationFunc
	Type string
}

type SimpleUser

type SimpleUser struct {
	ID         int64
	IDStr      string
	Name       string
	ScreenName string
}

type Tweet

type Tweet anaconda.Tweet

func (Tweet) ContainsGIF

func (t Tweet) ContainsGIF() bool

func (Tweet) ContainsOnlyText

func (t Tweet) ContainsOnlyText() bool

func (Tweet) ContainsPhoto

func (t Tweet) ContainsPhoto() bool

func (Tweet) ContainsVideo

func (t Tweet) ContainsVideo() bool

func (Tweet) DownloadMediaTo

func (t Tweet) DownloadMediaTo(dirPath string) ([]string, error)

func (Tweet) GetFullText

func (t Tweet) GetFullText() string

func (Tweet) GetHashtags

func (t Tweet) GetHashtags() []string

func (Tweet) GetMediaURLs added in v0.3.0

func (t Tweet) GetMediaURLs() []string

func (Tweet) GetText

func (t Tweet) GetText() string

func (Tweet) GetTextURLs

func (t Tweet) GetTextURLs() []string

func (Tweet) GetUserMentions

func (t Tweet) GetUserMentions() []SimpleUser

type TweetEntity

type TweetEntity struct {
	Func   EntityFunc
	Entity string
}

type TweetMap

type TweetMap map[string]Tweet

func (TweetMap) Join

func (tms1 TweetMap) Join(tms2 TweetMap) TweetMap

func (TweetMap) Load

func (t TweetMap) Load(filepath string) error

func (TweetMap) Save

func (t TweetMap) Save(filepath string) error

type Tweets

type Tweets []Tweet

func (Tweets) Join

func (tm1 Tweets) Join(tm2 Tweets) Tweets

func (*Tweets) Load

func (t *Tweets) Load(filepath string) error

func (Tweets) Save

func (tweets Tweets) Save(filepath string) error

func (Tweets) ToMap

func (tweets Tweets) ToMap() TweetMap

type User

type User anaconda.User

func (User) GetBackgroundImageURL

func (u User) GetBackgroundImageURL() string

func (User) GetDescription

func (u User) GetDescription() string

func (User) GetEmail

func (u User) GetEmail() string

func (User) GetFavoritesCount

func (u User) GetFavoritesCount() int

func (User) GetFollowersCount

func (u User) GetFollowersCount() int

func (User) GetFollowingCount

func (u User) GetFollowingCount() int

func (User) GetID

func (u User) GetID() string

func (User) GetProfileImageURL

func (u User) GetProfileImageURL() string

func (User) GetScreenName

func (u User) GetScreenName() string

func (User) GetStatusCount

func (u User) GetStatusCount() int64

func (User) IsProtected

func (u User) IsProtected() bool

func (User) IsVerified

func (u User) IsVerified() bool

type UserMap

type UserMap map[string]User

func (UserMap) Load

func (u UserMap) Load(filepath string) error

func (UserMap) Save

func (u UserMap) Save(filepath string) error

type Users

type Users []User

func (Users) Save

func (users Users) Save(filepath string) error

func (Users) ToMap

func (u Users) ToMap() UserMap

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL