lib/ayadn/workers.rb in ayadn-1.6.0 vs lib/ayadn/workers.rb in ayadn-1.7.0
- old
+ new
@@ -116,43 +116,53 @@
table << :separator unless index + 1 == list.length
end
table
end
+ # builds a hash of hashes, each hash is a normalized post with post id as a key
def build_posts(data, niceranks = {})
- # builds a hash of hashes, each hash is a normalized post with post id as a key
+ # skip objects in blacklist unless force
posts = {}
data.each.with_index(1) do |post, index|
- if Databases.blacklist[post['source']['name'].downcase]
- Debug.skipped({source: post['source']['name']})
- next
+ unless Settings.options[:force]
+ if Databases.blacklist[post['source']['name'].downcase]
+ Debug.skipped({source: post['source']['name']})
+ next
+ end
end
- if Databases.blacklist["-@#{post['user']['username'].downcase}"]
- Debug.skipped({user: post['user']['username']})
- next
+ unless Settings.options[:force]
+ if Databases.blacklist["-@#{post['user']['username'].downcase}"]
+ Debug.skipped({user: post['user']['username']})
+ next
+ end
end
hashtags = extract_hashtags(post)
@skip = false
- hashtags.each do |h|
- if Databases.blacklist[h.downcase]
- @skip = true
- Debug.skipped({hashtag: h})
- break
+ unless Settings.options[:force]
+ hashtags.each do |h|
+ if Databases.blacklist[h.downcase]
+ @skip = true
+ Debug.skipped({hashtag: h})
+ break
+ end
end
end
next if @skip
mentions= []
post['entities']['mentions'].each { |m| mentions << m['name'] }
- mentions.each do |m|
- if Databases.blacklist["@#{m.downcase}"]
- @skip = true
- Debug.skipped({mention: m})
- break
+ unless Settings.options[:force]
+ mentions.each do |m|
+ if Databases.blacklist["@#{m.downcase}"]
+ @skip = true
+ Debug.skipped({mention: m})
+ break
+ end
end
end
next if @skip
+ # create custom objects from ADN response
if niceranks[post['user']['id'].to_i]
rank = niceranks[post['user']['id'].to_i][:rank]
is_human = niceranks[post['user']['id'].to_i][:is_human]
real_person = niceranks[post['user']['id'].to_i][:real_person]
else
@@ -240,27 +250,23 @@
end
posts
end
def extract_links(post)
- links = []
- post['entities']['links'].each { |l| links << l['url'] }
+ links = post['entities']['links'].map { |l| l['url'] }
unless post['annotations'].nil? || post['annotations'].empty?
post['annotations'].each do |ann|
if ann['type'] == "net.app.core.oembed"
links << ann['value']['embeddable_url'] if ann['value']['embeddable_url']
end
end
end
- links.uniq!
- links
+ links.uniq
end
def extract_hashtags(post)
- tags = []
- post['entities']['hashtags'].each { |h| tags << h['name'] }
- tags
+ post['entities']['hashtags'].map { |h| h['name'] }
end
def build_channels(data, options = {})
bucket = []
if options[:channels]
@@ -367,11 +373,20 @@
username = "me".chars
end
username.join
end
- def add_arobases_to_usernames args #TODO: replace
+ def remove_arobase_if_present args
+ args.map! do |username|
+ temp = username.chars
+ temp.shift if temp.first == "@"
+ temp.join
+ end
+ args
+ end
+
+ def add_arobases_to_usernames args #TODO: replace all these arobase legacy methods by a unique one
args.map do |username|
if username == 'me'
who_am_i
else
temp = username.chars
@@ -385,19 +400,10 @@
db = Databases.init(Dir.home + "/ayadn/accounts.db")
active = db['ACTIVE']
db[active][:handle]
end
- def remove_arobase_if_present args
- args.map! do |username|
- temp = username.chars
- temp.shift if temp.first == "@"
- temp.join
- end
- args
- end
-
def extract_users(resp)
users_hash = {}
resp['data'].each do |item|
users_hash[item['id']] = [item['username'], item['name'], item['you_follow'], item['follows_you']]
end
@@ -471,11 +477,10 @@
def links_from_posts(stream)
links = []
stream['data'].each do |post|
extract_links(post).each {|l| links << l}
end
- links.uniq!
- links
+ links.uniq
end
def all_but_me usernames
arr = usernames.select {|user| user != 'me'}
at(arr)