Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update event logs

  • Loading branch information...
commit 3703819a0e7110be4c1c7642dac5b2c5261dd953 1 parent a7efbf4
@geekdeepak authored
View
3  app/models/event_update.rb
@@ -1,3 +1,6 @@
class EventUpdate < ActiveRecord::Base
belongs_to :facebook_event
+# def identifier
+# self.facebook_event.identifier
+# end
end
View
32 jobs/event_update_cron.rb
@@ -0,0 +1,32 @@
+puts "***facebook event updates***"
+
+t1 = Time.now
+puts "================"
+puts Time.now.strftime("%Y%m%d-%H%M%S") + " : " + __FILE__ + " starting..."
+
+puts "\ngrabbing file lock....."
+if File.new(__FILE__).flock(File::LOCK_EX | File::LOCK_NB) == false
+ puts "*** can't lock file, another instance of script running? exiting"
+ exit 1
+end
+puts "obtained file lock... starting facebook api calls...\n"
+
+allevents = FacebookEvent.find(:all, :conditions => [ "end_time > ?", Time.now ])
+config = YAML::load(File.open("#{Rails.root}/config/facebook.yml"));
+gscc_app = FbGraph::Application.new(config['production']['app_id'])
+access_token = gscc_app.get_access_token(config['production']['client_secret'])
+allevents.each do |e|
+ ie = FbGraph::Event.new(e.identifier, :access_token => access_token).fetch;
+ if ie
+ puts 'adding entry for '+e.name
+ e.event_updates.create(:attending=>ie.attending.count,:maybe=>ie.maybe.count,:invited=>ie.invited.count)
+ puts 'entry added'
+ else
+ puts "event #{e.name} not found deleting..."
+ e.delete
+ end
+end
+
+t2 = Time.now
+puts Time.now.strftime("%Y%m%d-%H%M%S") + " : " + __FILE__ + " finished #{t2 - t1} secs"
+puts "================"
View
5 jobs/update_facebook.rb
@@ -43,9 +43,9 @@
page.events.each do |e|
ie = FbGraph::Event.new(e.identifier, :access_token => access_token).fetch;
- edatabase = FacebookEvent.find(:first, :conditions => [ "identifier = ?", ie.identifier ]);
if ie.updated_time > lutdatabase
puts "\n**found dirty facebook event - "+ie.name
+ edatabase = FacebookEvent.find(:first, :conditions => [ "identifier = ?", ie.identifier ]);
if edatabase
puts "***found database entry, updating the entry "+edatabase.name
edatabase.name = ie.name
@@ -70,9 +70,6 @@
puts "***saved "+edatabase.name
end
end
- puts "***event updates entered for "+edatabase.name
- edatabase.event_updates.create(:attending=>ie.attending.count,:maybe=>ie.maybe.count,:invited=>ie.invited.count)
- puts
end
View
1  jobs/wrap_update_facebook.sh
@@ -14,3 +14,4 @@ then
fi
rails runner ${basedir}/update_facebook.rb
+rails runner ${basedir}/event_update_cron.rb
Please sign in to comment.
Something went wrong with that request. Please try again.