Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.42 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'twitter'
  3. require 'yaml'
  4. require 'active_support/core_ext/numeric/time'
  5.  
  6.  
  7. @@config = YAML.load_file("config.yml") rescue nil || {}
  8.  
  9. def get_xdays()
  10.   Time.zone = 'Singapore'
  11.   x_days = (Time.zone.parse(@@config['misc']['target_date'])- Time.zone.now).to_i/1.day
  12. end
  13.  
  14. def send_tweet()
  15.   # Set up twitter
  16.   client = Twitter::REST::Client.new do |config|
  17.     config.consumer_key        = @@config['api']['consumer_key']
  18.     config.consumer_secret     = @@config['api']['consumer_secret']
  19.     config.access_token        = @@config['access']['token']
  20.     config.access_token_secret = @@config['access']['secret']
  21.   end
  22.  
  23.   # Check if there is a file
  24.   # I made the image names the # on jersey
  25.   File.file?("images/#{get_xdays()}.jpg") ? img_path = "images/#{get_xdays()}.jpg" : img_path = "images/404.jpg"
  26.  
  27.   # Use it to tweet!!!
  28.   client.update_with_media("OWWW YEAAAH!!! #{get_xdays()}", File.new(img_path))
  29.  
  30.   # ========= JUST MY NOTES =========
  31.   # OK so posting with just text is easy
  32.   # client.update("Test #{get_xdays()}  #{Time.new.strftime("%Y-%m-%d %H:%M:%S")}")
  33.  
  34.   # Even posting a tweet with photo on your server is easy
  35.   # client.update_with_media("test wit photo frm local", File.new('lebrick.png'))
  36.  
  37.   # Tweeting a photo from a URL needs another gem :(
  38.   # client.update_with_media("test wit photo", open(url))
  39.   # ========= JUST MY NOTES =========
  40.  
  41. end
  42.  
  43.  
  44. send_tweet()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement