An Idea for adding groups to Twitter
- Create a user to be the group
- Scrap the User’s feeds for replies
- Reply to all followers (group members) with the replies
So I created drew something together on gist to get the concept down. This uses the twitter gem, so you can just
sudo gem install twitter
Note: I have not tested any of this. This is just a quick outline of what I think a possible solution can.
Migration:
class MoveBannedEmailsAndBlockedUsersTableToUsersDb < ActiveRecord::Migration
def self.up
create_table :twitter_groups do |t|
t.string :name
t.datetime :last_updated
end
end
def self.down
drop_table :twitter_groups
end
end
Model:
class TwitterGroup
# name: STRING - Name of the Group
# last_updated: DATETIME - records last time feed was scraped
def login(username, password)
@twit = Twitter::Base.new(username || self.name, password)
end
def scrape_timeline
raise "Please login with login()" if @twit.nil?
@twit.replies(:since => self.last_updated).each |reply| do
send_to_members("#{reply.text.gsub(/^@[a-z_-]+\s/i,'')} from #{reply.user.name}")
end
self.last_updated = Time.now
end
def send_to_members(message)
raise "Please login with login()" if @twit.nil?
@twit.followers.each do |u|
@twit.post "@#{u.name} #{message}"
end
end
end
Then to use it you just create an instance of TwitterGroup and periodically call scrape_timeline, like crontab.
group_bot.rb:
#!/usr/bin/ruby
group=TwitterGroup.new
group.login('my_group','password')
group.scrape_timeline
crontab:
30 * * * * ruby group_bot.rb
Disclaimer: I have not tested this at all, this is still a rough draft. Please comment on whatever suggestions you have.
2 Comments
Dude, chee, this is wicked! I like the concept, its a great idea.
Yeah, I’ve wondered about groups on twitter as well. There was a site that claimed to do it but no one wants to go to another site for that. This looks sweet, Alex. Great idea.