-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_helper.rb
More file actions
59 lines (49 loc) · 1.42 KB
/
twitter_helper.rb
File metadata and controls
59 lines (49 loc) · 1.42 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
require 'rubygems'
require 'json'
require 'net/http'
require 'yaml'
require 'time'
require 'twitter'
require 'active_support/all'
require 'mysql'
require 'pry'
def loadyaml(yaml)
begin
return YAML::load(File.open(yaml))
rescue Exception => e
log_time("error loading #{yaml} - #{e.message}", 'error')
end
end
def setvars
@yml = loadyaml('config.yml')
@db = Mysql.real_connect(@yml['database']['host'], @yml['database']['user'], @yml['database']['password'], @yml['database']['database'])
@client = Twitter::REST::Client.new do |config|
config.consumer_key = @yml['twitter']['consumer_key']
config.consumer_secret = @yml['twitter']['consumer_secret']
config.access_token = @yml['twitter']['access_token']
config.access_token_secret = @yml['twitter']['access_token_secret']
end
end
def event
{:name => @yml['event'].first['name'],
:lat => @yml['event'].first['lat'],
:long => @yml['event'].first['long'],
:range => @yml['event'].first['range']}
end
def twitter_strings_to_db(string)
return 'NULL' if string.nil?
return "'" + Mysql.escape_string(string) + "'"
end
def twitter_dates_to_db(string)
"'" + DateTime.parse(string).strftime("%Y-%m-%d %H:%M") + "'"
end
def twitter_int_to_db(int)
return 'NULL' if int.nil?
return int
end
def twitter_lat_long_to_db(lat, long)
return 'NULL' if lat.nil? || long.nil?
return "POINT(#{lat}, #{long})"
end
setvars