MultiMC/MultiMC5 — pull request #627 by 02JanDal (2014-11-22 21:39:49+00:00)
Title: Add a ModMyMC feed

For this to work, the following script needs to run on the multimc.org server and write to a file accessible at files.multimc.org/modmymc.json (CC: @Forkk):
```ruby
require 'json'
require 'twitter'
require 'optparse'

options = {
user: 'ModMyMC',
outfile: 'modmymc.json',
tweets: 10,
update_interval: 5 * 60,
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
parser = OptionParser.new do |opts|
opts.banner = 'Usage: mmmupdater.rb [options]'
opts.on '-u', '--user USER', 'The user to track' do |v|
options[:user] = v
end
opts.on '-o', '--out FILE', 'File to write results to' do |v|
options[:outfile] = v
end
opts.on '-n', '--numtweets NUM', 'The number of tweets to store' do |v|
options[:tweets] = v.to_i
end
opts.on '-r', '--update-interval SECONDS', 'The time between each update' do |v|
options[:update_interval] = v.to_i
end
opts.on '--consumer-key KEY', 'Consumser key for the Twitter API' do |v|
options[:consumer_key] = v
end
opts.on '--consumer-secret KEY', 'Consumer secret for the Twitter API' do |v|
options[:consumer_secret] = v
end
opts.on '--access-token KEY', 'Access token for the Twitter API' do |v|
options[:access_token] = v
end
opts.on '--access-token-secret KEY', 'Access token secret for the Twitter API' do |v|
options[:access_token_secret] = v
end

opts.on '-h', '--help', 'Displays this help' do
puts opts
exit
end
end
parser.parse!

client = Twitter::REST::Client.new do |config|
config.consumer_key = options[:consumer_key]
config.consumer_secret = options[:consumer_secret]
config.access_token = options[:access_token]
config.access_token_secret = options[:access_token_secret]
end
latest = 1
tweets = []
while true do
puts 'Fetching tweets...'
list = []
client.user_timeline(options[:user], since_id: latest, count: 100, trim_user: true, exclude_replies: true).each do |tweet|
latest = [tweet.id, latest].max
list << {data: tweet.text, timestamp: tweet.created_at}
end
tweets = (list + tweets).first options[:tweets]
File.open options[:outfile], 'w' do |file|
file.write JSON.pretty_generate(tweets)
end
puts 'Done'
sleep options[:update_interval]
end
```