Permalink
Browse files

+kolejka - w jednej rundce obslugujemy tylko jeden artykul, zeby nie …

…dalo sie zaspamowac ludzi
  • Loading branch information...
MatmaRex committed Mar 13, 2012
1 parent 70ecda6 commit a0c5a92c55e12d5b571274302a9ad58e24abb28a
Showing with 30 additions and 23 deletions.
  1. +30 −23 zb.rb
View
53 zb.rb
@@ -61,20 +61,24 @@ def get_user_notification_settings
-titles = (Marshal.read File.binread 'zb-marshal' rescue list_of_titles())
+titles, queue = *(Marshal.read File.binread 'zb-marshal' rescue [list_of_titles(), []])
while true
- sleep 3*60
-
new_titles = list_of_titles()
user_notif_sett = get_user_notification_settings()
all_cats = user_notif_sett.map{|a| a[1]}.flatten.uniq
+ queue += (new_titles-titles)
- puts "Tick. %d total reports, %d new, %d users." % [new_titles.length, (new_titles-titles).length, user_notif_sett.length]
+ puts "Tick. %d total reports, %d new, %d users, %d queued." %
+ [new_titles.length, (new_titles-titles).length, user_notif_sett.length, queue.length]
+ \
- title_cats = (new_titles-titles).map{|title|
+ title = queue.shift
+ title = queue.shift while title && !new_titles.include?(title)
+
+ if title
p = Page.new title
out = []
if p.pageid and p.pageid!=-1
@@ -85,32 +89,35 @@ def get_user_notification_settings
out += categories.select{|c| all_cats.include? c}
end
end
-
- [title, out.uniq]
- }
-
-
- user_notif = {}
-
- title_cats.each do |title, cats|
- user_notif_sett.each do |user, wanted_cats|
- intersect = cats & wanted_cats
- if !intersect.empty?
- user_notif[user] ||= []
- user_notif[user] << [title, intersect]
+ title_cats = [[title, out.uniq]]
+
+
+ user_notif = {}
+
+ title_cats.each do |title, cats|
+ user_notif_sett.each do |user, wanted_cats|
+ intersect = cats & wanted_cats
+
+ if !intersect.empty?
+ user_notif[user] ||= []
+ user_notif[user] << [title, intersect]
+ end
end
end
+
+ user_notif.each do |user, articles|
+ puts "Notifying #{user} about #{articles.map{|a| a[0]}.join(', ')}."
+ notify_user_zb user, articles
+ end
end
- user_notif.each do |user, articles|
- puts "Notifying #{user} about #{articles.map{|a| a[0]}.join(', ')}."
- notify_user_zb user, articles
- end
titles = new_titles
- File.binwrite 'zb-marshal', Marshal.dump(titles)
+ File.binwrite 'zb-marshal', Marshal.dump([titles, queue])
+
+ sleep 3*60
end

0 comments on commit a0c5a92

Please sign in to comment.