Sha256: 9666dacbe12bb8e288e856157c92d27becb9ee7339577d58aff7934d309c713d

Contents?: true

Size: 1.64 KB

Versions: 11

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require 'twitter'
require 'json'
require 'mini_magick'
require 'open-uri'
require 'pry'

module Ebooks
  class Sync

    def self.run(botname, username)
      bot = Ebooks::Bot.get(botname)
      bot.configure
      source_user = username
      ebooks_user = bot.username
      user = bot.twitter.user(source_user)
      if user.profile_image_url then
        Ebooks::Sync::get(user.profile_image_url(:original), "image/#{source_user}_avatar")
        avatar = MiniMagick::Image.open("image/#{source_user}_avatar")
        avatar.flip
        avatar.write("image/#{ebooks_user}_avatar")
        avatar64 = Base64.encode64(File.read("image/#{ebooks_user}_avatar"))
        bot.twitter.update_profile_image(avatar64)
        p "Updated profile image for #{ebooks_user} from #{source_user}."
      else
        p "#{source_user} does not have a profile image to clone."
      end
      if user.profile_banner_url then
        Ebooks::Sync::get(user.profile_banner_url, "image/#{source_user}banner")
        banner = MiniMagick::Image.open("image/#{source_user}banner")
        banner.flip
        banner.write("image/#{ebooks_user}_banner")
        banner64 = Base64.encode64(File.read("image/#{ebooks_user}_banner"))
        bot.twitter.update_profile_banner(banner64)
        p "Updated cover image for #{ebooks_user} from #{source_user}."
      else
        p "#{source_user} does not have a cover image to clone."
      end
    end

    def self.get(url, destination)
      File.open(destination, "wb") do |saved_file|
        open(url, "rb") do |read_file|
          saved_file.write(read_file.read)
        end
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
twitter_ebooks_poll-3.2.3 lib/twitter_ebooks/sync.rb
twitter_ebooks_poll-3.2.2 lib/twitter_ebooks/sync.rb
twitter_ebooks_poll-3.2.1 lib/twitter_ebooks/sync.rb
twitter_ebooks_poll-3.2.0 lib/twitter_ebooks/sync.rb
foxdear_ebooks-3.1.8 lib/foxdear_ebooks/sync.rb
foxdear_ebooks-3.1.7 lib/foxdear_ebooks/sync.rb
bot_twitter_ebooks-3.3.2 lib/bot_twitter_ebooks/sync.rb
bot_twitter_ebooks-3.3.1 lib/bot_twitter_ebooks/sync.rb
bot_twitter_ebooks-3.3.0 lib/bot_twitter_ebooks/sync.rb
bot_twitter_ebooks-3.2.0 lib/bot_twitter_ebooks/sync.rb
bot_twitter_ebooks-0.0.0 lib/bot_twitter_ebooks/sync.rb