-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimTricksSender.rb
More file actions
59 lines (50 loc) · 1.51 KB
/
vimTricksSender.rb
File metadata and controls
59 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby -w
# Monitor an RSS feed, and post its articles to twitter.
require 'rubygems'
require 'twitter'
require 'simple-rss'
require 'shorturl'
require 'open-uri'
require 'mysql'
class Tweet
attr_accessor :username
attr_accessor :password
attr_accessor :tweet
def initialize(username = "vimtricks", password = "vim123")
@username = username
@password = password
end
def send_tweet
httpauth = Twitter::HTTPAuth.new(@username, @password)
twitter = Twitter::Base.new( httpauth )
twitter.update(@tweet)
end
end
begin
# connect to the MySQL server
dbh = Mysql.real_connect("localhost", "intuitim_Vim123", "kinkybr00mstick", "intuitim_vimtricks")
# get server version string and display it
puts "Server version: " + dbh.get_server_info
# issue a retrieval query, perform a fetch loop, print the row count, and free the result set
res = dbh.query("SELECT id, command, nexttweet FROM commands order by nexttweet limit 1")
id = 0
while row = res.fetch_row do
printf "%s, %s, %s\n", row[0], row[1], row[2]
tweet = Tweet.new
id = row[0]
tweet.tweet = row[1]
tweet.send_tweet
end
puts "Number of rows returned: #{res.num_rows}"
res.free
puts "id = #{id}"
dbh.query("UPDATE commands set nexttweet = nexttweet+1 where id = #{id}")
puts "Number of rows inserted: #{dbh.affected_rows}"
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
# disconnect from server
dbh.close if dbh
end