Class: BenevolentGaze::Cli
- Inherits:
-
Thor
- Object
- Thor
- BenevolentGaze::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/benevolent_gaze/cli.rb
Instance Method Summary collapse
- #add_user(device_name, name, image_url) ⇒ Object
- #assign_users ⇒ Object
- #bg_flair ⇒ Object
- #bulk_assign(csv_path) ⇒ Object
- #dump_csv(filename) ⇒ Object
- #install(uname, pass) ⇒ Object
- #kiosk ⇒ Object
- #tracker ⇒ Object
Instance Method Details
#add_user(device_name, name, image_url) ⇒ Object
30 31 32 33 |
# File 'lib/benevolent_gaze/cli.rb', line 30 def add_user(device_name, name, image_url) `redis-cli set "name:#{device_name}" "#{name}"` `redis-cli set "image:#{name}" "#{image_url}"` end |
#assign_users ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/benevolent_gaze/cli.rb', line 36 def assign_users # users = `redis-cli hgetall "current_devices"`.split("\n") require 'redis' redis = Redis.new users = redis.hgetall "current_devices" puts "Right now, these are the devices on your network" users.each { |u,v| puts " #{u}" } users.each do |u, val| val = redis.get "name:#{u}" if val.nil? || val.empty? puts "Do you know whose device this is #{u}? ( y/n )" response = $stdin.gets.chomp.strip if response == "y" puts "Please enter their name." name_response = $stdin.gets.chomp.strip redis.set "name:#{u}", "#{name_response}" # `redis-cli set "name:#{u}" "#{name_response}"` puts "Do you have an image for this user? ( y/n )" image_response = $stdin.gets.chomp.strip if image_response == "y" puts "Please enter the image url." image_url_response = $stdin.gets.chomp.strip redis.set "image:#{name_response}", image_url_response end end else puts "#{Thor::Shell::Color::MAGENTA}#{u} looks like it has a name already associated with them.#{Thor::Shell::Color::CLEAR}" end end self.bg_flair end |
#bg_flair ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/benevolent_gaze/cli.rb', line 138 def bg_flair @bg = " \#{Thor::Shell::Color::CYAN}\n____ _ _ _____ \n | _ \\\\ | | | | / ____| \n | |_) | ___ _ __ _____ _____ | | ___ _ __ | |_ | | __ __ _ _______ \n | _ < / _ \\\\ '_ \\\\ / _ \\\\ \\\\ / / _ \\\\| |/ _ \\\\ '_ \\\\| __| | | |_ |/ _` |_ / _ \\\\\n | |_) | __/ | | | __/\\\\ V / (_) | | __/ | | | |_ | |__| | (_| |/ / __/\n |____/ \\\\___|_| |_|\\\\___| \\\\_/ \\\\___/|_|\\\\___|_| |_|\\\\__| \\\\_____|\\\\__,_/___\\\\___|\n\n \#{Thor::Shell::Color::CLEAR}\n BG\n puts @bg\nend\n" |
#bulk_assign(csv_path) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/benevolent_gaze/cli.rb', line 88 def bulk_assign(csv_path) CSV.foreach(csv_path) do |row| puts "Loading device info for #{row[0]} -> #{row[1]}" device_name = row[0] real_name = row[1] image_url = row[2] unless real_name.nil? || real_name.empty? `redis-cli set "name:#{device_name}" "#{real_name}"` end unless image_url.nil? || image_url.empty? `redis-cli set "image:#{real_name}" "#{image_url}"` end end # puts `redis-cli keys "*"` puts "#{Thor::Shell::Color::MAGENTA}The CSV has now been added.#{Thor::Shell::Color::CLEAR}" self.bg_flair end |
#dump_csv(filename) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/benevolent_gaze/cli.rb', line 72 def dump_csv( filename ) require 'redis' redis = Redis.new users = redis.hgetall "current_devices" CSV.open( filename, "wb" ) do |out| users.each do |device, name| name = redis.get "name:#{device}" image = redis.get "image:#{name}" out << [device,name,image] end end self.bg_flair puts "#{filename} created" end |
#install(uname, pass) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/benevolent_gaze/cli.rb', line 109 def install(uname, pass) directory ".", "bg_public" env_file = "bg_public/.env" new_path = File.("./bg_public") gsub_file(env_file, /.*PUBLIC_FOLDER.*/, "PUBLIC_FOLDER=\"#{new_path}/public\"") gsub_file("bg_public/public/index.html", "happyfuncorp3", uname) gsub_file("bg_public/public/index.html", "happiness4u", pass) puts "\n \#{Thor::Shell::Color::MAGENTA}**************************************************\#{Thor::Shell::Color::CLEAR}\n\n Generated the bg_public folder where you should go to customize images and to run \n\n ```foreman start```\n\n Please modify the .env file with the relevant information mentioned in the README.\n\n You can now customize your kiosk, by switching out the graphics in the images folder.\n Please replace the images with the images of the same size.\n\n Uploaded images will save to your local filesystem if you do not supply AWS creds.\n\n \#{Thor::Shell::Color::MAGENTA}**************************************************\#{Thor::Shell::Color::CLEAR}\n CUSTOMIZE\n\n self.bg_flair\nend\n" |
#kiosk ⇒ Object
15 16 17 |
# File 'lib/benevolent_gaze/cli.rb', line 15 def kiosk BenevolentGaze::Kiosk.run! end |
#tracker ⇒ Object
20 21 22 |
# File 'lib/benevolent_gaze/cli.rb', line 20 def tracker BenevolentGaze::Tracker.run! end |