Guest User

Untitled

a guest
Aug 3rd, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'rubygems'
  4. require 'gmail'
  5. require 'net/scp'
  6.  
  7. class PostPhoto
  8.  
  9. def initialize
  10. @username = 'xxxxxxxxxx@xxxxxxxxxx.xxxxxxxxx'
  11. @password = 'xxxxxxxxxxxxxx'
  12. @pic_path = '/home/xxxxxxxxxxx/pictures/'
  13. end
  14.  
  15. def get_and_post_pic
  16. gmail = Gmail.new(@username, @password)
  17. gmail.inbox.emails(:unread, :from => 'xxxxxxxxxx@xxxxxxxxxxx.xxx').each do |email|
  18. unless email.attachments.empty?
  19. email.save_attachments_to(@pic_path)
  20. file_name = email.subject.gsub(/Pic /, '') + '.jpg'
  21. File.rename(@pic_path + 'photo.jpg', @pic_path + file_name)
  22. Net::SCP.upload!("xxxxxxxxxxx.xxxxx", "xxxxxxxxxxxx",
  23. @pic_path + file_name, "/var/www/xxxxxxxxxx.xxx/gpic/")
  24. end
  25. email.archive!
  26. end
  27. end
  28. end
  29.  
  30. PostPhoto.new.get_and_post_pic
Add Comment
Please, Sign In to add comment