<commit_before>require 'rubygems'
require 'sinatra'
require 'json'
require 'dotenv'
require 'mongoid'
require 'time'
require_relative 'models/card'
require_relative 'twitter'
require_relative 'twitter'

Dotenv.load
configure do
  enable :sessions

  mongoid_config_path = File.expand_path(File.join('config', 'mongoid.yml'), File.dirname(__FILE__))
  Mongoid.load!(mongoid_config_path)
  
  twitter_init

  #Seed Content for testing
  #nowUTCDate = Time.now.to_i
  #newCard = Card.new(content: "This is my card content", image: "images/spaceappslogo.png", sequence_number: 1, published_time: nowUTCDate)
  #newCard.save!
end

helpers do
  def username
    session[:identity] ? session[:identity] : 'Hello stranger'
  end
end

before '/secure/*' do
  if !session[:identity] then
    session[:previous_url] = request.path
    @error = 'Sorry guacamole, you need to be logged in to visit ' + request.path
    halt erb(:login_form)
  end
end

get '/' do
  erb :index, :locals => {:launchName => "SpaceX CRS-6 Launch", :launchHastag => "#CRS6"}
end

get '/admin' do
  erb :admin, :locals => {:launchName => "ADMIN PANEL - - - SpaceX CRS-6 Launch", :launchHastag => "#CRS6}
end

get '/cards' do 
  after = params[:after]
  afterDateTime = DateTime.new(2000,1,1)
  if(!after.empty? && after != "null")
    afterDateTime =  DateTime.iso8601(after)
  end 

  messages = []
  Card.where(:published_time.gt => afterDateTime).each do |card|
    messages.append({:id => card.id, :message => card.content, :name => "Bob", :imageURI => card.image, :sequenceNumber => card.sequence_number, :publishedTime => card.published_time.to_s})
  end
  
  #Demo Content
  #messages.append({:id => 1,
  #      :message => 'this is the awesome message', 
  #      :title => 'This is the title', 
  #      :name => 'Bob',
  #      :imageURI => 'http://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Wild_Turkeys.jpg/250px-Wild_Turkeys.jpg'});
  #messages.append({:id => 2,
  #       :message => 'this is another awesome message', 
	#			 :title => 'This is another title', 
	#			 :name => 'Dave'});
   
  content_type :json
  messages.to_json
  
end<commit_msg>Oops.<commit_after>require 'rubygems'
require 'sinatra'
require 'json'
require 'dotenv'
require 'mongoid'
require 'time'
require_relative 'models/card'
require_relative 'twitter'
require_relative 'twitter'

Dotenv.load
configure do
  enable :sessions

  mongoid_config_path = File.expand_path(File.join('config', 'mongoid.yml'), File.dirname(__FILE__))
  Mongoid.load!(mongoid_config_path)
  
  twitter_init

  #Seed Content for testing
  #nowUTCDate = Time.now.to_i
  #newCard = Card.new(content: "This is my card content", image: "images/spaceappslogo.png", sequence_number: 1, published_time: nowUTCDate)
  #newCard.save!
end

helpers do
  def username
    session[:identity] ? session[:identity] : 'Hello stranger'
  end
end

before '/secure/*' do
  if !session[:identity] then
    session[:previous_url] = request.path
    @error = 'Sorry guacamole, you need to be logged in to visit ' + request.path
    halt erb(:login_form)
  end
end

get '/' do
  erb :index, :locals => {:launchName => "SpaceX CRS-6 Launch", :launchHastag => "#CRS6"}
end

get '/admin' do
  erb :admin, :locals => {:launchName => "ADMIN PANEL - - - SpaceX CRS-6 Launch", :launchHastag => "#CRS6"}
end

get '/cards' do 
  after = params[:after]
  afterDateTime = DateTime.new(2000,1,1)
  if(!after.empty? && after != "null")
    afterDateTime =  DateTime.iso8601(after)
  end 

  messages = []
  Card.where(:published_time.gt => afterDateTime).each do |card|
    messages.append({:id => card.id, :message => card.content, :name => "Bob", :imageURI => card.image, :sequenceNumber => card.sequence_number, :publishedTime => card.published_time.to_s})
  end
  
  #Demo Content
  #messages.append({:id => 1,
  #      :message => 'this is the awesome message', 
  #      :title => 'This is the title', 
  #      :name => 'Bob',
  #      :imageURI => 'http://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Wild_Turkeys.jpg/250px-Wild_Turkeys.jpg'});
  #messages.append({:id => 2,
  #       :message => 'this is another awesome message', 
	#			 :title => 'This is another title', 
	#			 :name => 'Dave'});
   
  content_type :json
  messages.to_json
  
end
{'fraction_non_alphanumeric': 0.14926073691621686, 'fraction_numerical': 0.00985684111710866, 'mean_word_length': 3.9214780600461894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1724858', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1455, 'n_words': 359}