ayadn 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/ayadn/action.rb +5 -1
- data/lib/ayadn/api.rb +84 -9
- data/lib/ayadn/blacklist.rb +12 -12
- data/lib/ayadn/cnx.rb +28 -1
- data/lib/ayadn/databases.rb +35 -12
- data/lib/ayadn/errors.rb +6 -1
- data/lib/ayadn/logs.rb +22 -16
- data/lib/ayadn/scroll.rb +59 -2
- data/lib/ayadn/set.rb +10 -0
- data/lib/ayadn/settings.rb +10 -2
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +1 -0
- data/lib/ayadn/workers.rb +45 -6
- data/lib/ayadn.rb +6 -6
- data/spec/unit/workers_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50a5231b4bcda461e9adfb2d2ad0cb7ecddaee40
|
|
4
|
+
data.tar.gz: c6dda497fe8883e4449ba446c9e9c4800c0b5891
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65a41024fa6f58361b67e37c74df7ad4d0d69341fe2880f53047544d7ee06b5aaf5d3ba9cd8ab669dd57f7be1f0dfaf6105e4e4705fbff6351c7d8f72c98e952
|
|
7
|
+
data.tar.gz: 2a95a67105ef3211717874682109d103a60b5dd6fdf464db67f2f15637c78dd3bee22aac17364bfb5063e321075ed08c03297562785cee40a04c5902d120c906
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# 1.2.3 - 'Taylor'
|
|
2
|
+
|
|
3
|
+
- Text containing '#' but not an hashtag: not colorized
|
|
4
|
+
- Add/remove several elements to/from blacklist at once
|
|
5
|
+
- Cached results for NiceRank (expire = 24h)
|
|
6
|
+
- NiceRank filter works better
|
|
7
|
+
- NiceRank logs missed users ids in a separate file
|
|
8
|
+
- Option for showing debug messages
|
|
9
|
+
- Show spinner = true
|
|
10
|
+
|
|
1
11
|
# 1.2.2 - 'Chris'
|
|
2
12
|
|
|
3
13
|
- No more empty lines in the scroll
|
data/lib/ayadn/action.rb
CHANGED
|
@@ -48,7 +48,11 @@ module Ayadn
|
|
|
48
48
|
options[:filter] = true
|
|
49
49
|
doing(options)
|
|
50
50
|
stream = @api.get_global(options)
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
###DEBUG
|
|
53
|
+
#niceranks = @api.get_niceranks stream
|
|
54
|
+
niceranks, _ = @api.get_niceranks stream, 0
|
|
55
|
+
|
|
52
56
|
(no_new_posts unless Databases.has_new?(stream, 'global')) if options[:new]
|
|
53
57
|
Databases.save_max_id(stream)
|
|
54
58
|
render_view(stream, options, niceranks)
|
data/lib/ayadn/api.rb
CHANGED
|
@@ -200,22 +200,97 @@ module Ayadn
|
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
###DEBUG
|
|
204
|
+
#def get_niceranks stream
|
|
205
|
+
def get_niceranks stream, iter
|
|
206
|
+
###DEBUG
|
|
207
|
+
@iter = iter
|
|
208
|
+
|
|
204
209
|
user_ids, table, niceranks = [], {}, {}
|
|
205
210
|
stream['data'].each do |post|
|
|
206
211
|
user_ids << post['user']['id'].to_i
|
|
207
212
|
table[post['user']['id'].to_i] = post['user']['username']
|
|
208
213
|
end
|
|
209
214
|
user_ids.uniq!
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
|
|
216
|
+
db_ranks = Databases.get_niceranks user_ids
|
|
217
|
+
get_these = []
|
|
218
|
+
db_ranks.each do |id,ranks|
|
|
219
|
+
if ranks.nil?
|
|
220
|
+
get_these << id
|
|
221
|
+
elsif (Time.now - ranks[:cached]) > 86400 # 24 hours cache
|
|
222
|
+
get_these << id
|
|
223
|
+
else
|
|
224
|
+
niceranks[id] = {
|
|
225
|
+
username: ranks[:username],
|
|
226
|
+
rank: ranks[:rank],
|
|
227
|
+
is_human: ranks[:is_human],
|
|
228
|
+
cached: ranks[:cached]
|
|
229
|
+
}
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
234
|
+
puts "=====\nNiceRanks\n".color(Settings.options[:colors][:debug])
|
|
235
|
+
puts "From DB:\t#{niceranks}\n".color(Settings.options[:colors][:debug])
|
|
236
|
+
puts "To get:\t\t#{get_these}\n=====\n".color(Settings.options[:colors][:debug])
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
unless get_these.empty?
|
|
240
|
+
req = "http://api.search-adn.net/user/nicerank?ids=#{get_these.join(',')}"
|
|
241
|
+
resp = JSON.parse(CNX.get req)
|
|
242
|
+
|
|
243
|
+
#Error handling
|
|
244
|
+
if resp['meta']['code'] != 200
|
|
245
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
246
|
+
puts "=====\nNiceRank:\tError #{resp['meta']['code']} (#{resp['meta']['time']})\n=====\n".color(Settings.options[:colors][:debug])
|
|
247
|
+
end
|
|
248
|
+
Errors.nr "REQUESTED: #{get_these.join(' ')}"
|
|
249
|
+
|
|
250
|
+
###DEBUG
|
|
251
|
+
@iter += 1
|
|
252
|
+
|
|
253
|
+
if niceranks
|
|
254
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
255
|
+
puts "=====\nNiceRanks:\t#{niceranks}".color(Settings.options[:colors][:debug])
|
|
256
|
+
puts "=====\n".color(Settings.options[:colors][:debug])
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
#return niceranks
|
|
260
|
+
|
|
261
|
+
###DEBUG
|
|
262
|
+
return niceranks, @iter
|
|
263
|
+
else
|
|
264
|
+
|
|
265
|
+
# return {}
|
|
266
|
+
|
|
267
|
+
###DEBUG
|
|
268
|
+
return {}, @iter
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
###DEBUG
|
|
273
|
+
@iter += 1
|
|
274
|
+
|
|
275
|
+
resp['data'].each do |obj|
|
|
276
|
+
niceranks[obj['user_id']] = {
|
|
277
|
+
username: table[obj['user_id']],
|
|
278
|
+
rank: obj['rank'],
|
|
279
|
+
is_human: obj['is_human'],
|
|
280
|
+
cached: Time.now
|
|
281
|
+
}
|
|
282
|
+
end
|
|
283
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
284
|
+
puts "=====\nNiceRanks:\t#{niceranks}".color(Settings.options[:colors][:debug])
|
|
285
|
+
puts "Resp:\t\t#{resp}".color(Settings.options[:colors][:debug])
|
|
286
|
+
puts "=====\n".color(Settings.options[:colors][:debug])
|
|
287
|
+
end
|
|
217
288
|
end
|
|
218
|
-
niceranks
|
|
289
|
+
Databases.add_niceranks niceranks
|
|
290
|
+
|
|
291
|
+
###DEBUG
|
|
292
|
+
#niceranks
|
|
293
|
+
return niceranks, @iter
|
|
219
294
|
end
|
|
220
295
|
|
|
221
296
|
def get_channels
|
data/lib/ayadn/blacklist.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Ayadn
|
|
|
4
4
|
desc "add TYPE TARGET", "Adds a mention, hashtag or client to your blacklist"
|
|
5
5
|
long_desc Descriptions.blacklist_add
|
|
6
6
|
def add(*args)
|
|
7
|
-
if args.length
|
|
7
|
+
if args.length < 2
|
|
8
8
|
puts Status.type_and_target_missing
|
|
9
9
|
end
|
|
10
10
|
blacklist = BlacklistWorkers.new
|
|
@@ -15,7 +15,7 @@ module Ayadn
|
|
|
15
15
|
desc "remove TYPE TARGET", "Removes a mention, hashtag or client from your blacklist"
|
|
16
16
|
long_desc Descriptions.blacklist_remove
|
|
17
17
|
def remove(*args)
|
|
18
|
-
if args.length
|
|
18
|
+
if args.length < 2
|
|
19
19
|
puts Status.type_and_target_missing
|
|
20
20
|
end
|
|
21
21
|
blacklist = BlacklistWorkers.new
|
|
@@ -80,18 +80,18 @@ module Ayadn
|
|
|
80
80
|
end
|
|
81
81
|
def add(args)
|
|
82
82
|
begin
|
|
83
|
-
type
|
|
83
|
+
type = args.shift
|
|
84
84
|
case type
|
|
85
85
|
when 'mention', 'mentions'
|
|
86
|
-
target = Workers.
|
|
86
|
+
target = Workers.add_arobases_to_usernames args
|
|
87
87
|
Databases.add_mention_to_blacklist(target)
|
|
88
88
|
Logs.rec.info "Added '#{target}' to blacklist of mentions."
|
|
89
89
|
when 'client', 'source'
|
|
90
|
-
Databases.add_client_to_blacklist(
|
|
91
|
-
Logs.rec.info "Added '#{
|
|
90
|
+
Databases.add_client_to_blacklist(args)
|
|
91
|
+
Logs.rec.info "Added '#{args}' to blacklist of clients."
|
|
92
92
|
when 'hashtag', 'tag'
|
|
93
|
-
Databases.add_hashtag_to_blacklist(
|
|
94
|
-
Logs.rec.info "Added '#{
|
|
93
|
+
Databases.add_hashtag_to_blacklist(args)
|
|
94
|
+
Logs.rec.info "Added '#{args}' to blacklist of hashtags."
|
|
95
95
|
else
|
|
96
96
|
puts Status.wrong_arguments
|
|
97
97
|
end
|
|
@@ -101,15 +101,15 @@ module Ayadn
|
|
|
101
101
|
end
|
|
102
102
|
def remove(args)
|
|
103
103
|
begin
|
|
104
|
-
type
|
|
104
|
+
type = args.shift
|
|
105
105
|
case type
|
|
106
106
|
when 'mention', 'mentions'
|
|
107
|
-
target = Workers.
|
|
107
|
+
target = Workers.add_arobases_to_usernames args
|
|
108
108
|
Databases.remove_from_blacklist(target)
|
|
109
109
|
Logs.rec.info "Removed '#{target}' from blacklist of mentions."
|
|
110
110
|
when 'client', 'source', 'hashtag', 'tag'
|
|
111
|
-
Databases.remove_from_blacklist(
|
|
112
|
-
Logs.rec.info "Removed '#{type}:#{
|
|
111
|
+
Databases.remove_from_blacklist(args)
|
|
112
|
+
Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
|
|
113
113
|
else
|
|
114
114
|
puts Status.wrong_arguments
|
|
115
115
|
end
|
data/lib/ayadn/cnx.rb
CHANGED
|
@@ -5,7 +5,9 @@ module Ayadn
|
|
|
5
5
|
def self.get url
|
|
6
6
|
begin
|
|
7
7
|
RestClient.get(url) do |response, request, result|
|
|
8
|
-
response
|
|
8
|
+
debug(response, url) if Settings.options[:timeline][:show_debug] == true
|
|
9
|
+
#response
|
|
10
|
+
check_nr response, url
|
|
9
11
|
end
|
|
10
12
|
rescue SocketError => e
|
|
11
13
|
puts "\nConnection error.".color(:red)
|
|
@@ -18,9 +20,31 @@ module Ayadn
|
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
def self.check_nr response, url
|
|
24
|
+
case response.code
|
|
25
|
+
when 200
|
|
26
|
+
response
|
|
27
|
+
when 204
|
|
28
|
+
puts "\nError: the NiceRank filter made too many requests to the server. You may either wait for a little while before scrolling the filtered Global again, or set the scroll timer to a greater value (example: `ayadn set scroll timer 5`). You can also let the unranked posts appear in the stream if you prefer (see http://ayadn-app.net/doc).\n".color(:red)
|
|
29
|
+
Errors.global_error("cnx.rb/get", [url, response.inspect, response.headers], "NiceRank: TOO MANY REQUESTS")
|
|
30
|
+
else
|
|
31
|
+
response
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.debug response, url
|
|
36
|
+
puts ":::::".color(Settings.options[:colors][:debug])
|
|
37
|
+
puts "Url:\t\t#{url}\n".color(Settings.options[:colors][:debug])
|
|
38
|
+
#puts "Resp:\t\t#{response.code}\n".color(Settings.options[:colors][:debug])
|
|
39
|
+
puts "Headers:\t#{response.headers}\n".color(Settings.options[:colors][:debug])
|
|
40
|
+
puts "Remaining:\t#{response.headers[:x_ratelimit_remaining]}".color(Settings.options[:colors][:debug])
|
|
41
|
+
puts ":::::\n".color(Settings.options[:colors][:debug])
|
|
42
|
+
end
|
|
43
|
+
|
|
21
44
|
def self.get_response_from(url)
|
|
22
45
|
begin
|
|
23
46
|
RestClient.get(url) do |response, request, result| #, :verify_ssl => OpenSSL::SSL::VERIFY_NONE
|
|
47
|
+
debug(response, url) if Settings.options[:timeline][:show_debug] == true
|
|
24
48
|
check(response)
|
|
25
49
|
end
|
|
26
50
|
rescue SocketError => e
|
|
@@ -73,6 +97,7 @@ module Ayadn
|
|
|
73
97
|
begin
|
|
74
98
|
#RestClient::Resource.new(url).delete
|
|
75
99
|
RestClient.delete(url) do |response, request, result|
|
|
100
|
+
debug(response, url) if Settings.options[:timeline][:show_debug] == true
|
|
76
101
|
check(response)
|
|
77
102
|
end
|
|
78
103
|
rescue SocketError => e
|
|
@@ -89,6 +114,7 @@ module Ayadn
|
|
|
89
114
|
def self.post(url, payload = nil)
|
|
90
115
|
begin
|
|
91
116
|
RestClient.post(url, payload.to_json, :content_type => :json, :accept => :json) do |response, request, result|
|
|
117
|
+
debug(response, url) if Settings.options[:timeline][:show_debug] == true
|
|
92
118
|
check(response)
|
|
93
119
|
end
|
|
94
120
|
rescue SocketError => e
|
|
@@ -105,6 +131,7 @@ module Ayadn
|
|
|
105
131
|
def self.put(url, payload)
|
|
106
132
|
begin
|
|
107
133
|
RestClient.put(url, payload.to_json, :content_type => :json, :accept => :json) do |response, request, result|
|
|
134
|
+
debug(response, url) if Settings.options[:timeline][:show_debug] == true
|
|
108
135
|
check(response)
|
|
109
136
|
end
|
|
110
137
|
rescue SocketError => e
|
data/lib/ayadn/databases.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Ayadn
|
|
|
4
4
|
class Databases
|
|
5
5
|
|
|
6
6
|
class << self
|
|
7
|
-
attr_accessor :users, :index, :pagination, :aliases, :blacklist, :bookmarks
|
|
7
|
+
attr_accessor :users, :index, :pagination, :aliases, :blacklist, :bookmarks, :nicerank
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def self.open_databases
|
|
@@ -14,37 +14,60 @@ module Ayadn
|
|
|
14
14
|
@aliases = self.init "#{Settings.config[:paths][:db]}/aliases.db"
|
|
15
15
|
@blacklist = self.init "#{Settings.config[:paths][:db]}/blacklist.db"
|
|
16
16
|
@bookmarks = self.init "#{Settings.config[:paths][:db]}/bookmarks.db"
|
|
17
|
+
@nicerank = self.init "#{Settings.config[:paths][:db]}/nicerank.db"
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def self.close_all
|
|
20
|
-
[@users, @index, @pagination, @aliases, @blacklist, @bookmarks].each do |db|
|
|
21
|
-
db.compact
|
|
21
|
+
[@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank].each do |db|
|
|
22
22
|
db.flush
|
|
23
|
+
db.compact
|
|
23
24
|
db.close
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def self.init(path)
|
|
28
|
-
winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
|
|
29
|
-
case RbConfig::CONFIG['host_os']
|
|
30
|
-
when *winPlatforms
|
|
31
|
-
|
|
32
|
-
else
|
|
29
|
+
# winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
|
|
30
|
+
# case RbConfig::CONFIG['host_os']
|
|
31
|
+
# when *winPlatforms
|
|
32
|
+
# abort("\nSorry, Ayadn doesn't work on Windows.\n\n".color(:red))
|
|
33
|
+
# else
|
|
33
34
|
Daybreak::DB.new "#{path}"
|
|
35
|
+
# end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.add_niceranks niceranks
|
|
39
|
+
niceranks.each do |id,infos|
|
|
40
|
+
@nicerank[id] = infos
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.get_niceranks user_ids
|
|
45
|
+
ids = {}
|
|
46
|
+
user_ids.each do |id|
|
|
47
|
+
ids[id] = @nicerank[id]
|
|
34
48
|
end
|
|
49
|
+
ids
|
|
35
50
|
end
|
|
36
51
|
|
|
37
52
|
def self.add_mention_to_blacklist(target)
|
|
38
|
-
|
|
53
|
+
target.each do |username|
|
|
54
|
+
@blacklist[username.downcase] = :mention
|
|
55
|
+
end
|
|
39
56
|
end
|
|
40
57
|
def self.add_client_to_blacklist(target)
|
|
41
|
-
|
|
58
|
+
target.each do |source|
|
|
59
|
+
@blacklist[source.downcase] = :client
|
|
60
|
+
end
|
|
42
61
|
end
|
|
43
62
|
def self.add_hashtag_to_blacklist(target)
|
|
44
|
-
|
|
63
|
+
target.each do |tag|
|
|
64
|
+
@blacklist[tag.downcase] = :hashtag
|
|
65
|
+
end
|
|
45
66
|
end
|
|
46
67
|
def self.remove_from_blacklist(target)
|
|
47
|
-
|
|
68
|
+
target.each do |el|
|
|
69
|
+
@blacklist.delete(el.downcase)
|
|
70
|
+
end
|
|
48
71
|
end
|
|
49
72
|
def self.import_blacklist(blacklist)
|
|
50
73
|
new_list = self.init blacklist
|
data/lib/ayadn/errors.rb
CHANGED
|
@@ -11,7 +11,9 @@ module Ayadn
|
|
|
11
11
|
Logs.rec.debug "STACK: #{caller}"
|
|
12
12
|
Logs.rec.error "--END--"
|
|
13
13
|
puts "\n(error logged in #{Settings.config[:paths][:log]}/ayadn.log)\n".color(:blue)
|
|
14
|
-
|
|
14
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
15
|
+
raise error
|
|
16
|
+
end
|
|
15
17
|
exit
|
|
16
18
|
end
|
|
17
19
|
def self.error(status)
|
|
@@ -26,6 +28,9 @@ module Ayadn
|
|
|
26
28
|
def self.repost(repost, original)
|
|
27
29
|
Logs.rec.info "Post #{repost} is a repost. Using original: #{original}."
|
|
28
30
|
end
|
|
31
|
+
def self.nr msg
|
|
32
|
+
Logs.nr.warn msg
|
|
33
|
+
end
|
|
29
34
|
|
|
30
35
|
private
|
|
31
36
|
|
data/lib/ayadn/logs.rb
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
module Ayadn
|
|
3
3
|
class Logs
|
|
4
|
+
|
|
4
5
|
class << self
|
|
5
|
-
attr_accessor :rec
|
|
6
|
+
attr_accessor :rec, :nr
|
|
6
7
|
end
|
|
8
|
+
|
|
7
9
|
def self.create_logger
|
|
8
10
|
@rec = Logger.new(Settings.config[:paths][:log] + "/ayadn.log", 'monthly')
|
|
9
11
|
@rec.formatter = proc do |severity, datetime, progname, msg|
|
|
10
12
|
"#{datetime} (#{Settings.config[:version]}) #{severity} -- #{msg}\n"
|
|
11
13
|
end
|
|
14
|
+
@nr = Logger.new(Settings.config[:paths][:log] + "/nicerank.log", 'monthly')
|
|
15
|
+
@nr.formatter = proc do |severity, datetime, progname, msg|
|
|
16
|
+
"#{datetime} (#{Settings.config[:version]}) #{severity} -- #{msg}\n"
|
|
17
|
+
end
|
|
12
18
|
end
|
|
13
19
|
|
|
14
20
|
# unused (experiment)
|
|
15
|
-
def self.send_log(from, args, content)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
21
|
+
# def self.send_log(from, args, content)
|
|
22
|
+
# begin
|
|
23
|
+
# log = {
|
|
24
|
+
# "platform" => "#{Settings.config[:platform]}",
|
|
25
|
+
# "date" => Time.now,
|
|
26
|
+
# "version" => "#{Settings.config[:version]}",
|
|
27
|
+
# "source" => from,
|
|
28
|
+
# "args" => args,
|
|
29
|
+
# "content" => content
|
|
30
|
+
# }
|
|
31
|
+
# Post.new.send_log(log)
|
|
32
|
+
# rescue
|
|
33
|
+
# @rec.warn("Unable to send log.")
|
|
34
|
+
# end
|
|
35
|
+
# end
|
|
30
36
|
|
|
31
37
|
end
|
|
32
38
|
end
|
data/lib/ayadn/scroll.rb
CHANGED
|
@@ -20,18 +20,43 @@ module Ayadn
|
|
|
20
20
|
def scroll_it(target, options, niceranks)
|
|
21
21
|
options = check_raw(options)
|
|
22
22
|
orig_target = target
|
|
23
|
+
|
|
24
|
+
###DEBUG
|
|
25
|
+
@iter = 0
|
|
26
|
+
@adn = 1
|
|
27
|
+
|
|
23
28
|
loop do
|
|
24
29
|
begin
|
|
25
30
|
stream = get(target, options)
|
|
31
|
+
|
|
32
|
+
###DEBUG
|
|
33
|
+
@adn += 1
|
|
34
|
+
|
|
26
35
|
if options[:filter] == true
|
|
27
36
|
unless stream['data'].empty?
|
|
28
|
-
|
|
37
|
+
###DEBUG
|
|
38
|
+
#niceranks = @api.get_niceranks stream
|
|
39
|
+
niceranks, @iter = @api.get_niceranks stream, @iter
|
|
40
|
+
###DEBUG
|
|
41
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
42
|
+
puts "@@@@@\nADN calls:\t#{@adn}\n".color(Settings.options[:colors][:debug])
|
|
43
|
+
puts "NiceRank calls:\t#{@iter}".color(Settings.options[:colors][:debug])
|
|
44
|
+
puts "@@@@@\n".color(Settings.options[:colors][:debug])
|
|
45
|
+
end
|
|
29
46
|
else
|
|
30
|
-
|
|
47
|
+
niceranks = {}
|
|
31
48
|
end
|
|
32
49
|
else
|
|
33
50
|
niceranks = {}
|
|
34
51
|
end
|
|
52
|
+
|
|
53
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
54
|
+
puts "+++++\nStream meta:\t#{stream['meta']}\n".color(Settings.options[:colors][:debug])
|
|
55
|
+
puts "Options:\t#{options.inspect}\n".color(Settings.options[:colors][:debug])
|
|
56
|
+
puts "Target:\t\t#{target.inspect}\n".color(Settings.options[:colors][:debug])
|
|
57
|
+
puts "Posts:\t\t#{stream['data'].length}\n+++++\n".color(Settings.options[:colors][:debug])
|
|
58
|
+
end
|
|
59
|
+
|
|
35
60
|
target = "explore:#{target}" if explore?(target)
|
|
36
61
|
show_if_new(stream, options, target, niceranks)
|
|
37
62
|
target = orig_target if target =~ /explore/
|
|
@@ -50,6 +75,14 @@ module Ayadn
|
|
|
50
75
|
loop do
|
|
51
76
|
begin
|
|
52
77
|
stream = @api.get_mentions(username, options)
|
|
78
|
+
|
|
79
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
80
|
+
puts "+++++\nStream meta:\t#{stream['meta']}\n".color(Settings.options[:colors][:debug])
|
|
81
|
+
puts "Options:\t#{options.inspect}\n".color(Settings.options[:colors][:debug])
|
|
82
|
+
puts "Target:\t\t#{username}\n".color(Settings.options[:colors][:debug])
|
|
83
|
+
puts "Posts:\t\t#{stream['data'].length}\n+++++\n".color(Settings.options[:colors][:debug])
|
|
84
|
+
end
|
|
85
|
+
|
|
53
86
|
show_if_new(stream, options, "mentions:#{id}")
|
|
54
87
|
options = save_then_return(stream, options)
|
|
55
88
|
countdown
|
|
@@ -66,6 +99,14 @@ module Ayadn
|
|
|
66
99
|
loop do
|
|
67
100
|
begin
|
|
68
101
|
stream = @api.get_posts(username, options)
|
|
102
|
+
|
|
103
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
104
|
+
puts "+++++\nStream meta:\t#{stream['meta']}\n".color(Settings.options[:colors][:debug])
|
|
105
|
+
puts "Options:\t#{options.inspect}\n".color(Settings.options[:colors][:debug])
|
|
106
|
+
puts "Target:\t\t#{username}\n".color(Settings.options[:colors][:debug])
|
|
107
|
+
puts "Posts:\t\t#{stream['data'].length}\n+++++\n".color(Settings.options[:colors][:debug])
|
|
108
|
+
end
|
|
109
|
+
|
|
69
110
|
show_if_new(stream, options, "posts:#{id}")
|
|
70
111
|
options = save_then_return(stream, options)
|
|
71
112
|
countdown
|
|
@@ -80,6 +121,14 @@ module Ayadn
|
|
|
80
121
|
loop do
|
|
81
122
|
begin
|
|
82
123
|
stream = @api.get_convo(post_id, options)
|
|
124
|
+
|
|
125
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
126
|
+
puts "+++++\nStream meta:\t#{stream['meta']}\n".color(Settings.options[:colors][:debug])
|
|
127
|
+
puts "Options:\t#{options.inspect}\n".color(Settings.options[:colors][:debug])
|
|
128
|
+
puts "Target:\t\t#{post_id}\n".color(Settings.options[:colors][:debug])
|
|
129
|
+
puts "Posts:\t\t#{stream['data'].length}\n+++++\n".color(Settings.options[:colors][:debug])
|
|
130
|
+
end
|
|
131
|
+
|
|
83
132
|
show_if_new(stream, options, "replies:#{post_id}")
|
|
84
133
|
options = save_then_return(stream, options)
|
|
85
134
|
countdown
|
|
@@ -94,6 +143,14 @@ module Ayadn
|
|
|
94
143
|
loop do
|
|
95
144
|
begin
|
|
96
145
|
stream = @api.get_messages(channel_id, options)
|
|
146
|
+
|
|
147
|
+
if Settings.options[:timeline][:show_debug] == true
|
|
148
|
+
puts "+++++\nStream meta:\t#{stream['meta']}\n".color(Settings.options[:colors][:debug])
|
|
149
|
+
puts "Options:\t#{options.inspect}\n".color(Settings.options[:colors][:debug])
|
|
150
|
+
puts "Target:\t\t#{channel_id}\n".color(Settings.options[:colors][:debug])
|
|
151
|
+
puts "Posts:\t\t#{stream['data'].length}\n+++++\n".color(Settings.options[:colors][:debug])
|
|
152
|
+
end
|
|
153
|
+
|
|
97
154
|
show_if_new(stream, options, "channel:#{channel_id}")
|
|
98
155
|
options = save_then_return(stream, options)
|
|
99
156
|
countdown
|
data/lib/ayadn/set.rb
CHANGED
|
@@ -379,6 +379,12 @@ module Ayadn
|
|
|
379
379
|
def show_spinner value
|
|
380
380
|
Settings.options[:timeline][:show_spinner] = value
|
|
381
381
|
end
|
|
382
|
+
def show_debug value
|
|
383
|
+
unless Settings.options[:colors][:debug]
|
|
384
|
+
Settings.options[:colors][:debug] = :cyan
|
|
385
|
+
end
|
|
386
|
+
Settings.options[:timeline][:show_debug] = value
|
|
387
|
+
end
|
|
382
388
|
end
|
|
383
389
|
|
|
384
390
|
class SetColor
|
|
@@ -446,5 +452,9 @@ module Ayadn
|
|
|
446
452
|
def symbols(color)
|
|
447
453
|
Settings.options[:colors][:symbols] = color.to_sym
|
|
448
454
|
end
|
|
455
|
+
|
|
456
|
+
def debug(color)
|
|
457
|
+
Settings.options[:colors][:debug] = color.to_sym
|
|
458
|
+
end
|
|
449
459
|
end
|
|
450
460
|
end
|
data/lib/ayadn/settings.rb
CHANGED
|
@@ -81,6 +81,12 @@ module Ayadn
|
|
|
81
81
|
# TODO: system to merge existing config file when future category are added
|
|
82
82
|
begin
|
|
83
83
|
@options = YAML.load(File.read(config_file))
|
|
84
|
+
if @options[:timeline][:show_debug].nil?
|
|
85
|
+
@options[:timeline][:show_debug] = false
|
|
86
|
+
end
|
|
87
|
+
if @options[:nicerank][:threshold]
|
|
88
|
+
@options[:nicerank][:threshold] = @options[:nicerank][:threshold].round
|
|
89
|
+
end
|
|
84
90
|
rescue => e
|
|
85
91
|
Errors.global_error("myconfig/load config.yml", nil, e)
|
|
86
92
|
end
|
|
@@ -153,7 +159,8 @@ module Ayadn
|
|
|
153
159
|
show_real_name: true,
|
|
154
160
|
show_date: true,
|
|
155
161
|
show_nicerank: false,
|
|
156
|
-
show_spinner:
|
|
162
|
+
show_spinner: true,
|
|
163
|
+
show_debug: false
|
|
157
164
|
},
|
|
158
165
|
counts: {
|
|
159
166
|
default: 50,
|
|
@@ -190,7 +197,8 @@ module Ayadn
|
|
|
190
197
|
mentions: :red,
|
|
191
198
|
source: :cyan,
|
|
192
199
|
symbols: :green,
|
|
193
|
-
nicerank: :cyan
|
|
200
|
+
nicerank: :cyan,
|
|
201
|
+
debug: :red
|
|
194
202
|
},
|
|
195
203
|
backup: {
|
|
196
204
|
auto_save_sent_posts: false,
|
data/lib/ayadn/version.rb
CHANGED
data/lib/ayadn/view.rb
CHANGED
data/lib/ayadn/workers.rb
CHANGED
|
@@ -117,8 +117,10 @@ module Ayadn
|
|
|
117
117
|
|
|
118
118
|
if niceranks[post['user']['id'].to_i]
|
|
119
119
|
rank = niceranks[post['user']['id'].to_i][:rank]
|
|
120
|
+
is_human = niceranks[post['user']['id'].to_i][:is_human]
|
|
120
121
|
else
|
|
121
122
|
rank = false
|
|
123
|
+
is_human = 'unknown'
|
|
122
124
|
end
|
|
123
125
|
|
|
124
126
|
if post['user'].has_key?('name')
|
|
@@ -137,6 +139,7 @@ module Ayadn
|
|
|
137
139
|
username: post['user']['username'],
|
|
138
140
|
user_id: post['user']['id'].to_i,
|
|
139
141
|
nicerank: rank,
|
|
142
|
+
is_human: is_human,
|
|
140
143
|
handle: "@#{post['user']['username']}",
|
|
141
144
|
type: post['user']['type'],
|
|
142
145
|
date: parsed_time(post['created_at']),
|
|
@@ -162,7 +165,7 @@ module Ayadn
|
|
|
162
165
|
|
|
163
166
|
unless post['text'].nil?
|
|
164
167
|
values[:raw_text] = post['text']
|
|
165
|
-
values[:text] = colorize_text(post['text'], mentions)
|
|
168
|
+
values[:text] = colorize_text(post['text'], mentions, hashtags)
|
|
166
169
|
else
|
|
167
170
|
values[:raw_text] = ""
|
|
168
171
|
values[:text] = "(no text)"
|
|
@@ -262,16 +265,35 @@ module Ayadn
|
|
|
262
265
|
|
|
263
266
|
def self.add_arobase_if_missing(username) # expects an array of username(s), works on the first one and outputs a string
|
|
264
267
|
unless username.first == "me"
|
|
265
|
-
username = username.first.chars
|
|
268
|
+
username = username.first.chars
|
|
266
269
|
username.unshift("@") unless username.first == "@"
|
|
267
270
|
else
|
|
268
|
-
username = "me".chars
|
|
271
|
+
username = "me".chars
|
|
269
272
|
end
|
|
270
273
|
username.join
|
|
271
274
|
end
|
|
272
275
|
|
|
276
|
+
def self.add_arobases_to_usernames args
|
|
277
|
+
args.map! do |username|
|
|
278
|
+
if username == 'me'
|
|
279
|
+
self.who_am_i
|
|
280
|
+
else
|
|
281
|
+
temp = username.chars
|
|
282
|
+
temp.unshift("@") unless temp.first == "@"
|
|
283
|
+
temp.join
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
args
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def self.who_am_i
|
|
290
|
+
db = Databases.init(Dir.home + "/ayadn/accounts.db")
|
|
291
|
+
active = db['ACTIVE']
|
|
292
|
+
db[active][:handle]
|
|
293
|
+
end
|
|
294
|
+
|
|
273
295
|
def self.remove_arobase_if_present(username)
|
|
274
|
-
username = username.chars
|
|
296
|
+
username = username.chars
|
|
275
297
|
username.shift if username.first == "@"
|
|
276
298
|
username.join
|
|
277
299
|
end
|
|
@@ -284,7 +306,7 @@ module Ayadn
|
|
|
284
306
|
users_hash
|
|
285
307
|
end
|
|
286
308
|
|
|
287
|
-
def colorize_text(text, mentions)
|
|
309
|
+
def colorize_text(text, mentions, hashtags)
|
|
288
310
|
reg_split = '[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]'
|
|
289
311
|
#reg_tag = '#([A-Za-z0-9_]{1,255})(?![\w+])'
|
|
290
312
|
reg_tag = '#([[:alpha:]0-9_]{1,255})(?![\w+])'
|
|
@@ -299,7 +321,24 @@ module Ayadn
|
|
|
299
321
|
text.scan(/#{reg_sentence}/) do |sentence|
|
|
300
322
|
sentence.split(' ').each do |word|
|
|
301
323
|
if word =~ /#\w+/
|
|
302
|
-
|
|
324
|
+
slices = word.split('#')
|
|
325
|
+
has_h = false
|
|
326
|
+
slices.each do |tag|
|
|
327
|
+
bit = tag.downcase.scan(/[[:alpha:]0-9_]/).join('')
|
|
328
|
+
if hashtags.include? bit
|
|
329
|
+
has_h = true
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
if has_h == true
|
|
333
|
+
if slices.length > 1
|
|
334
|
+
word = slices.join('#')
|
|
335
|
+
words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
|
|
336
|
+
else
|
|
337
|
+
words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
|
|
338
|
+
end
|
|
339
|
+
else
|
|
340
|
+
words << word
|
|
341
|
+
end
|
|
303
342
|
elsif word =~ /@\w+/
|
|
304
343
|
@str = def_str(word, reg_split)
|
|
305
344
|
if handles.include?(@str.downcase)
|
data/lib/ayadn.rb
CHANGED
|
@@ -3,11 +3,11 @@ require_relative 'ayadn/version'
|
|
|
3
3
|
|
|
4
4
|
%w{rest_client json thor rainbow/ext/string terminal-table yaml logger daybreak fileutils io/console}.each { |r| require "#{r}" }
|
|
5
5
|
|
|
6
|
-
winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
|
|
7
|
-
case Gem::Platform.local.os
|
|
8
|
-
when *winPlatforms
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
6
|
+
# winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
|
|
7
|
+
# case Gem::Platform.local.os
|
|
8
|
+
# when *winPlatforms
|
|
9
|
+
# require 'win32console'
|
|
10
|
+
# require 'pstore'
|
|
11
|
+
# end
|
|
12
12
|
|
|
13
13
|
require_relative 'ayadn/app'
|
data/spec/unit/workers_spec.rb
CHANGED
|
@@ -149,7 +149,7 @@ describe Ayadn::Workers do
|
|
|
149
149
|
it "colorizes mentions and hashtags" do
|
|
150
150
|
text = regex_post['data']['text']
|
|
151
151
|
mentions = regex_post['data']['entities']['mentions']
|
|
152
|
-
expect(Ayadn::Workers.new.colorize_text(text, mentions)).to eq "\e[36m#test\e[0m \e[36m#regex\e[0m\n@aya_tests's \e[36m#true\e[0m\n(@aya_tests) \e[36m#true\e[0m\n@AyA_TeSts \e[36m#true\e[0m\n@aya_test \e[36m#false\e[0m\naya@aya_tests.yolo \e[36m#false\e[0m\n-@aya_tests:ohai! \e[36m#true\e[0m\ntext,@aya_tests,txt \e[36m#true\e[0m"
|
|
152
|
+
expect(Ayadn::Workers.new.colorize_text(text, mentions, ['false', 'true', 'test', 'regex'])).to eq "\e[36m#test\e[0m \e[36m#regex\e[0m\n@aya_tests's \e[36m#true\e[0m\n(@aya_tests) \e[36m#true\e[0m\n@AyA_TeSts \e[36m#true\e[0m\n@aya_test \e[36m#false\e[0m\naya@aya_tests.yolo \e[36m#false\e[0m\n-@aya_tests:ohai! \e[36m#true\e[0m\ntext,@aya_tests,txt \e[36m#true\e[0m"
|
|
153
153
|
end
|
|
154
154
|
end
|
|
155
155
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ayadn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Dejonckheere
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-05-
|
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|