-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
74 lines (58 loc) · 1.5 KB
/
app.rb
File metadata and controls
74 lines (58 loc) · 1.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'twitter'
require 'sinatra'
set :server, 'webrick'
get '/' do
erb :index
end
post '/results' do
parser = Parser.new(params)
@identities = parser.identities
@topics = parser.topics
@tweets = parser.tweets
@topic_results = parser.topic_results
erb :results
end
class Parser
attr_accessor(:identities, :topics)
def initialize(params)
@identities = params[:identities]
@topics = params[:topics]
@client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['CONSUMER_KEY']
config.consumer_secret = ENV['CONSUMER_SECRET']
config.access_token = ENV['ACCESS_TOKEN']
config.access_token_secret = ENV['ACCESS_TOKEN_SECRET']
end
end
def tweets
@identities.split(", ").map do |screen_name|
@client.user_timeline("#{screen_name}", :count => 200).map do |tweet|
{"#{screen_name}" => tweet.to_h[:text]}
end
end
end
# def topic_count
# @topic_count = []
# @topics.split(", ").each do |topic|
# tweets.each do |el|
# el.each do |el|
# topic_count << el.count if el.each{|el| el.include?("#{topic}")}
# end
# end
# end
# return @topic_count
# end
def topic_results
@results = []
@topics.split(", ").each do |topic|
tweets.each do |el|
el.each do |el|
el.each do |k,v|
@results << "#{k}=> #{v}\n" if v.include?("#{topic}")
end
end
end
end
return @results
end
end