Added sync command
This commit is contained in:
parent
8bbe22f55c
commit
8bf15d2a1b
4 changed files with 75 additions and 0 deletions
21
bin/ebooks
21
bin/ebooks
|
@ -28,6 +28,7 @@ Usage:
|
||||||
ebooks append <model_name> <corpus_path>
|
ebooks append <model_name> <corpus_path>
|
||||||
ebooks gen <model_path> [input]
|
ebooks gen <model_path> [input]
|
||||||
ebooks archive <username> [path]
|
ebooks archive <username> [path]
|
||||||
|
ebooks sync <botname> [username]
|
||||||
ebooks tweet <model_path> <botname>
|
ebooks tweet <model_path> <botname>
|
||||||
ebooks version
|
ebooks version
|
||||||
STR
|
STR
|
||||||
|
@ -227,6 +228,25 @@ STR
|
||||||
Ebooks::Archive.new(username, outpath).sync
|
Ebooks::Archive.new(username, outpath).sync
|
||||||
end
|
end
|
||||||
|
|
||||||
|
HELP.sync = <<-STR
|
||||||
|
Usage: ebooks sync <botname> <username>
|
||||||
|
|
||||||
|
Copies and flips <username>'s avatar and cover photo, uploading them to <botname>'s profile.
|
||||||
|
|
||||||
|
Stores saved avatar's and covers in image/.
|
||||||
|
|
||||||
|
STR
|
||||||
|
|
||||||
|
def self.sync(botname, username)
|
||||||
|
if botname.nil?
|
||||||
|
help :sync
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
load File.join(APP_PATH, 'bots.rb')
|
||||||
|
Ebooks::Sync::run(botname, username)
|
||||||
|
end
|
||||||
|
|
||||||
HELP.tweet = <<-STR
|
HELP.tweet = <<-STR
|
||||||
Usage: ebooks tweet <model_path> <botname>
|
Usage: ebooks tweet <model_path> <botname>
|
||||||
|
|
||||||
|
@ -409,6 +429,7 @@ STR
|
||||||
when "append" then append(args[1],args[2])
|
when "append" then append(args[1],args[2])
|
||||||
when "gen" then gen(args[1], args[2..-1].join(' '))
|
when "gen" then gen(args[1], args[2..-1].join(' '))
|
||||||
when "archive" then archive(args[1], args[2])
|
when "archive" then archive(args[1], args[2])
|
||||||
|
when "sync" then sync(args[1], args[2])
|
||||||
when "tweet" then tweet(args[1], args[2])
|
when "tweet" then tweet(args[1], args[2])
|
||||||
when "jsonify" then jsonify(args[1..-1])
|
when "jsonify" then jsonify(args[1..-1])
|
||||||
when "auth" then auth
|
when "auth" then auth
|
||||||
|
|
|
@ -16,6 +16,7 @@ end
|
||||||
|
|
||||||
require 'twitter_ebooks/nlp'
|
require 'twitter_ebooks/nlp'
|
||||||
require 'twitter_ebooks/archive'
|
require 'twitter_ebooks/archive'
|
||||||
|
require 'twitter_ebooks/sync'
|
||||||
require 'twitter_ebooks/suffix'
|
require 'twitter_ebooks/suffix'
|
||||||
require 'twitter_ebooks/model'
|
require 'twitter_ebooks/model'
|
||||||
require 'twitter_ebooks/bot'
|
require 'twitter_ebooks/bot'
|
||||||
|
|
52
lib/twitter_ebooks/sync.rb
Normal file
52
lib/twitter_ebooks/sync.rb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/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
|
|
@ -33,4 +33,5 @@ Gem::Specification.new do |gem|
|
||||||
gem.add_runtime_dependency 'highscore'
|
gem.add_runtime_dependency 'highscore'
|
||||||
gem.add_runtime_dependency 'pry'
|
gem.add_runtime_dependency 'pry'
|
||||||
gem.add_runtime_dependency 'oauth'
|
gem.add_runtime_dependency 'oauth'
|
||||||
|
gem.add_runtime_dependency 'mini_magick'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue