tweethog

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: MIT Imports: 24 Imported by: 0

README

TweetHog - Stream, filter and react to Twitter status updates

Build Status Code Quality GitHub issues MIT License

This tool provides an easy way to stream, filter and optionally react (like, follow, save image, log,...) to tweets based on topic, language and user profile. It is similar to commercial SaaS offerings such as TweetFull, RoboLike or Twitfox. However...

  • TweetHog is free, fast and doesn't require setting up a server
  • You stay in control of your data and don't need to give access to your Twitter account
  • You can improve your Go skills if you choose to adapt it to your specific needs

TweetHog

Installation

Make sure you got Go version >= 1.11 installed on your computer. It can be downloaded for free at https://golang.org/dl/. You might need to install Xcode and agree to its license first on OS X.

Then open a terminal and enter:

go get github.com/lastzero/tweethog/cmd/tweethog

To update it afterwards:

go get -u github.com/lastzero/tweethog/cmd/tweethog

Note: Your PATH, GOPATH and GOROOT environment variables need to be set correctly for go get to work as expected.

Configuration

In order to stream status updates, TweetHog needs access to the Twitter API:

  1. Copy config.example.yml to ~/.tweethog
  2. Create your own Twitter API keys & tokens on https://apps.twitter.com/app/new
  3. Put them in ~/.tweethog by replacing the placeholders

Hint: You can use the --config-file flag to use a different config file.

Note: Due to an issue with the go-twitter library, you won't see any error when using invalid credentials. See comments.

Example Usage

# tweethog filter -t cat
2017/10/27 07:29:47 Starting Twitter stream...

2017/10/27 07:30:08 m$hawtyyy @xmvdieee (Following: 136, Followers: 167, Likes: 1885)
someone get me a cat

2017/10/27 07:30:43 Eldar @Eldurr (Following: 228, Followers: 477, Likes: 3512)
I need a vacation, just told the cat to get the fuck outta here

2017/10/27 07:30:50 Oying Alvarado @oyingalvarado (Following: 195, Followers: 9, Likes: 2447)
There’s a disconcerting lack of cat tweets today

Commands

Command Description
config Displays all configuration values
auth Requests a user access token and secret for the Twitter API
filter Shows all matching tweets without performing any action
like Automatically likes all matching tweets
follow Automatically follows all users with matching tweets
smartlike Likes tweets with random delay and rate limit

Global Flags

Name Description
--config-file value, -c value YAML config filename (default: "~/.tweethog")
--consumer-key value Twitter API consumer key
--consumer-secret value Twitter API consumer secret
--access-token value Twitter API user access token
--access-secret value Twitter API user access token secret

Filter Flags

Name Description
--topic value, -t value Stream filter topic e.g. cat, dog, fish
--lang value, -l value Stream filter language e.g. en, de, fr
--min-followers value User min followers (default: 0)
--max-followers value User max followers, 0 for unlimited (default: 0)
--min-following value User min following (default: 0)
--max-following value User max following, 0 for unlimited (default: 0)
--max-tags value Max number of hash #tags (default: 0)
--max-mentions value Max number of @mentions (default: 0)
--retweets Include tweets starting with RT
--replies Include tweets starting with @
--via Include tweets containing via @
--urls Include tweets containing URLs
--images-only Only tweets containing images

Other Flags

Name Description
--save-images value Save all images in a directory
--json-log value Log matching tweets in a file as newline delimited JSON

Default Values

All of the flags can be set in the config file as a default. Example:

max-mentions: 1
max-tags: 2
lang: en
urls: true
retweets: false
replies: false
via: false

Run tweethog config to see the current values.

About

This tool was created by Michael Mayer in an attempt to learn Go the agile way: Start with something small that works and then refactor and improve. You can use it for free and at your own risk under the terms of the MIT license.

Please feel free to send an e-mail if you have any questions or just want to say hello. Contributions are most welcome, even if it's just a bug report or a tiny pull-request to fix a typo.

Documentation

Overview

This tool provides an easy way to stream, filter and optionally react (like, follow, save image, log,...) to tweets based on topic, language and user profile.

Index

Constants

View Source
const (
	CompactTime = "2006/01/02 15:04:05"
)

Variables

This section is empty.

Functions

func CliAuth added in v0.8.0

func CliAuth(consumerKey string, consumerSecret string)

func GetExpandedFilename added in v0.7.0

func GetExpandedFilename(filename string) string

func GetRandomInt

func GetRandomInt(min, max int) int

Types

type Config

type Config struct {
	// API credentials
	ConsumerKey    string
	ConsumerSecret string
	AccessToken    string
	AccessSecret   string

	// YAML config file name
	ConfigFile string
	JsonLog    string
	SaveImages string

	// Tweet filter
	Filter *Filters
}

func NewConfig

func NewConfig() *Config

func (*Config) SetValuesFromCliContext

func (config *Config) SetValuesFromCliContext(c *cli.Context) error

func (*Config) SetValuesFromFile

func (config *Config) SetValuesFromFile(fileName string) error

type Filters added in v0.6.1

type Filters struct {
	Topics       []string
	Languages    []string
	MinFollowers int
	MaxFollowers int
	MinFollowing int
	MaxFollowing int
	MaxTags      int
	MaxMentions  int
	Retweets     bool
	Replies      bool
	Via          bool
	URLs         bool
	ImagesOnly   bool
}

type LastAction

type LastAction struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type Status

type Status struct {
	// contains filtered or unexported fields
}

func NewStatus

func NewStatus(tweet *twitter.Tweet, stream *Stream) *Status

func (*Status) ContainsImage added in v0.7.0

func (status *Status) ContainsImage() bool

func (*Status) ContainsUrl

func (status *Status) ContainsUrl() bool

func (*Status) Follow added in v0.8.0

func (status *Status) Follow()

func (*Status) GetAllUrls added in v0.7.0

func (status *Status) GetAllUrls() []string

func (*Status) GetAsJson added in v0.6.1

func (status *Status) GetAsJson() (string, error)

func (*Status) GetCreatedAt

func (status *Status) GetCreatedAt() *time.Time

func (*Status) GetFavouritesCount

func (status *Status) GetFavouritesCount() int

func (*Status) GetFollowersCount

func (status *Status) GetFollowersCount() int

func (*Status) GetFriendsCount

func (status *Status) GetFriendsCount() int

func (*Status) GetID

func (status *Status) GetID() int64

func (*Status) GetIDString added in v0.7.0

func (status *Status) GetIDString() string

func (*Status) GetImageUrl added in v0.7.0

func (status *Status) GetImageUrl() string

func (*Status) GetName added in v0.6.1

func (status *Status) GetName() string

func (*Status) GetScreenName

func (status *Status) GetScreenName() string

func (*Status) GetText

func (status *Status) GetText() string

func (*Status) IsReply

func (status *Status) IsReply() bool

func (*Status) IsRetweet

func (status *Status) IsRetweet() bool

func (*Status) Like

func (status *Status) Like()

func (*Status) MatchesFilter added in v0.6.1

func (status *Status) MatchesFilter(filter *Filters) bool

func (*Status) SaveImageToFile added in v0.7.0

func (status *Status) SaveImageToFile(path string) (string, error)

func (*Status) SmartLike

func (status *Status) SmartLike()

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func NewStream

func NewStream(config *Config) *Stream

func (*Stream) GetConfig

func (stream *Stream) GetConfig() *Config

func (*Stream) Start

func (stream *Stream) Start(action func(status *Status)) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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