Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Twitter List agent #2229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sentience
Copy link
Contributor

@sentience sentience commented Feb 21, 2018

The Twitter List Agent receives tweets from the users that belong to a Twitter list. I use this to receive push notifications from a subset of the users that I follow – my “I want to hear about it near-instantly when these users post something” list.

This uses the lists/statuses method of the Twitter API to fetch periodically a list of tweets with the specified criteria.

An ideal implementation might instead fetch a list of users in the specified list (and refresh that list periodically), and then monitor a filtered stream containing only the tweets of those users with Twitter’s streaming API, using the same mechanism as Twitter Stream Agent. This would have the benefit of generating events in real time; however, I did not have the time necessary to invest in this more complex implementation.

@sentience
Copy link
Contributor Author

I just realised I omitted tests for this agent. If this contribution is otherwise acceptable, let me know and I’ll work up some unit tests to add to this PR.

Copy link
Collaborator

@dsander dsander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realised I omitted tests for this agent. If this contribution is otherwise acceptable, let me know and I’ll work up some unit tests to add to this PR.

Yes, please add some specs. The Agent looks useful to me and simple enough to have it in Huginn itself.

An ideal implementation might instead fetch a list of users in the specified list (and refresh that list periodically), and then monitor a filtered stream containing only the tweets of those users with Twitter’s streaming API, using the same mechanism as Twitter Stream Agent. This would have the benefit of generating events in real time; however, I did not have the time necessary to invest in this more complex implementation.

Interesting idea, the only problem could be lists with a lot of members as the Stream API has some limitations on how many keywords/users can be tracked.

end

def starting_at
if interpolated[:starting_at].present?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be

def starting_at
  return created_at unless interpolated[:starting_at].present?
  Time.parse(interpolated[:starting_at]) rescue created_at
end


def check
since_id = memory['since_id'] || nil
opts = {:count => 200, :include_rts => include_retweets?, :include_entities => true, tweet_mode: 'extended'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the "new" ruby Hash syntax like count: 200.

def check
since_id = memory['since_id'] || nil
opts = {:count => 200, :include_rts => include_retweets?, :include_entities => true, tweet_mode: 'extended'}
opts.merge! :since_id => since_id unless since_id.nil?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

end

tweets.each do |tweet|
if tweet.created_at >= starting_at
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid the nesting by bailing out of the loop early:

next if tweet.created_at < starting_at

@zoomequipd
Copy link
Contributor

I don't know anything about how to build tests for these things, but this is a feature I'd love to use. @sentience is there any chance I can convince you to brush off the dust on this one? Or publish it has a third party module?

@sentience
Copy link
Contributor Author

@zoomequipd I'm afraid I have one too many things to do already to get around to adding the missing specs here in the very near future.

You're welcome to grab the file from this pull request and drop it into your installation to add it if you want to use it for now.

@romans8
Copy link

romans8 commented Jan 21, 2021

I also have some interest in this feature. Thought I would add my name to the hat.

@sentience
Copy link
Contributor Author

@zoomequipd @romans8 and anyone else who wants this feature: I've published my Twitter List Agent as a gem here: https://github.com/sentience/huginn_twitter_list_agent

You can add this to your Huginn instance using the ADDITIONAL_GEMS environment variable, as shown in .env.example:

ADDITIONAL_GEMS=huginn_twitter_list_agent(github: sentience/huginn_twitter_list_agent, branch: main)

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants