Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'gmail'
- require 'net/scp'
- class PostPhoto
- def initialize
- @username = 'xxxxxxxxxx@xxxxxxxxxx.xxxxxxxxx'
- @password = 'xxxxxxxxxxxxxx'
- @pic_path = '/home/xxxxxxxxxxx/pictures/'
- end
- def get_and_post_pic
- gmail = Gmail.new(@username, @password)
- gmail.inbox.emails(:unread, :from => 'xxxxxxxxxx@xxxxxxxxxxx.xxx').each do |email|
- unless email.attachments.empty?
- email.save_attachments_to(@pic_path)
- file_name = email.subject.gsub(/Pic /, '') + '.jpg'
- File.rename(@pic_path + 'photo.jpg', @pic_path + file_name)
- Net::SCP.upload!("xxxxxxxxxxx.xxxxx", "xxxxxxxxxxxx",
- @pic_path + file_name, "/var/www/xxxxxxxxxx.xxx/gpic/")
- end
- email.archive!
- end
- end
- end
- PostPhoto.new.get_and_post_pic
Add Comment
Please, Sign In to add comment