Permalink
Browse files

fixed APRS

  • Loading branch information...
1 parent 993b818 commit 67ab68ffe84c76e6d808be37775ba674dc193687 @chrismatthieu committed Jun 4, 2011
@@ -17,7 +17,12 @@ def login
if @u and @p.user.is_admin
# @u = User.find_by_login(params[:login])
- @u = User.find(:first, :conditions => ['login ILIKE ?', params[:login]])
+ if request.url.index('localhost')
+ @u = User.find(:first, :conditions => ['login LIKE ?', params[:login]])
+ else
+ @u = User.find(:first, :conditions => ['login ILIKE ?', params[:login]])
+ end
+
flash[:notice] = "Hello #{@u.f rescue ''}"
# cookies[:auth_token] = {:expires => Time.now-1.day, :value => "" }
@@ -6,7 +6,11 @@ def callsign
#@user = User.find_by_login(@callsign)
# @user = User.find(:first, :conditions => ['login = ?', @callsign])
- @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @user = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
# if @user
@@ -97,7 +97,11 @@ def callsign
#@user = User.find_by_login(@callsign)
# @userx = User.find(:first, :conditions => ['login = ?', @callsign])
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @userx
@@ -262,7 +262,11 @@ def graph
#@user = User.find_by_login(@callsign)
# @userx = User.find(:first, :conditions => ['login = ?', @callsign])
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @userx
@@ -373,7 +373,13 @@ def callsign
else
# @userx = User.find_by_login(@callsign)
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
+
# LOCALHOST use LIKE for mysql
@callelements = Array.new
@@ -137,7 +137,12 @@ def callsign
# @user = User.find_by_login(@callsign)
# @userx = User.find(:first, :conditions => ['login = ?', @callsign])
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @userx
@@ -52,7 +52,12 @@ def callsign
#@user = User.find_by_login(@callsign)
# @userx = User.find(:first, :conditions => ['login = ?', @callsign])
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @userx
@@ -129,7 +129,12 @@ def callsign
#@user = User.find_by_login(@callsign)
# @user = User.find(:first, :conditions => ['login = ?', @callsign])
- @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @user = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @user
@@ -2,12 +2,13 @@
require 'rubygems'
require 'open-uri'
require 'cgi'
+require 'json'
class StatusesController < ApplicationController
- skip_filter :login_required, :only => [:callsign, :index, :hamfeed]
- before_filter :setup, :except => [:callsign, :hamfeed]
+ skip_filter :login_required, :only => [:callsign, :index, :hamfeed, :poll]
+ before_filter :setup, :except => [:callsign, :hamfeed, :poll]
include Net
@@ -207,7 +208,12 @@ def callsign
#@user = User.find_by_login(@callsign)
# @userx = User.find(:first, :conditions => ['login = ?', @callsign])
- @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @userx = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @userx = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @userx
@@ -280,6 +286,109 @@ def friends
end
end
+ def poll
+
+ # APRS.FI APIKEY = 27286.QJTmrxJGMvlNh
+ # http://api.aprs.fi/api/get?what=msg&dst=N7ICE&apikey=27286.QJTmrxJGMvlNh&format=json
+ # {"command":"get","result":"ok","found":1,"what":"msg","entries":[{"messageid":"19963994","time":"1307195053","srccall":"73S","dst":"N7ICE","message":"N7ICE-test from 73s via 73s.org"}]}
+
+ @aprsupdate = Aprsupdate.find(:first)
+ #OPENAPRS - DEFAULT TIMEZONE: America/Los_Angeles
+ #TimeStamp is in Unix timestamp epoch format Time.now.to_i
+
+
+ #@published = (@aprsupdate.published + 7.hours).to_i #UTC = -5 hours at server location
+ #@published = @aprsupdate.published.to_i #UTC
+ @published = (@aprsupdate.published - 6.minutes).to_i #do get around a slow clock on open aprs
+
+ @aprs = open("http://api.aprs.fi/api/get?what=msg&dst=73S&apikey=27286.QJTmrxJGMvlNh&format=json") {|f| f.read }
+ result = JSON.parse(@aprs)
+
+ result["entries"].each do |msg|
+ if msg["time"].to_i > @published
+
+ @source = msg['srccall']
+ @rawmsg = msg['message']
+ @message = @rawmsg + ' via APRS'
+
+ if !@rawmsg.blank?
+
+ @txtarray = @rawmsg.split(" ")
+
+ if @txtarray[0].downcase == "time"
+
+ @time = Time.now.gmtime
+
+ aprsmsg = 'Current Time is ' + @time.to_s + ' UTC via 73s.org'
+ @url = 'http://www.findu.com/cgi-bin/sendmsg.cgi?fromcall=73S&tocall=' + @source.upcase + '&msg=' + CGI.escape(aprsmsg)
+ @results = open(@url).read
+
+
+ elsif @txtarray[0].downcase == "echo"
+
+ @data = @rawmsg.split('echo')
+ aprsmsg = @data[1].strip() + ' via 73s.org'
+ @url = 'http://www.findu.com/cgi-bin/sendmsg.cgi?fromcall=73S&tocall=' + @source.upcase + '&msg=' + CGI.escape(aprsmsg)
+ @results = open(@url).read
+
+ else
+
+ #update 73s status
+ #NEED TO ACCOUNT FOR SUFFIX HANDLING
+ @rootsource = @source.split("-")
+ @source = @rootsource[0]
+
+ if request.url.index('localhost')
+ @callsign = User.find(:first, :conditions => ['login LIKE ?', @source])
+ else
+ @callsign = User.find(:first, :conditions => ['login ILIKE ?', @source])
+ end
+
+ @status = Status.new
+
+ if @callsign
+ @status.profile_id = @callsign.profile.id
+ else
+ @status.profile_id = 1
+ end
+
+ @status.message = @message
+ @status.save
+
+ #retweeting
+ if @callsign and @callsign.access_token
+ @tweet = @message + " - http://73s.org/" + @callsign.login
+
+ if @tweet.length > 133
+ @tweet = @tweet[0..130] + "..."
+ end
+
+ @client = TwitterOAuth::Client.new(
+ :consumer_key => '5Yr0l7nhb8JbwCpnsxyCA',
+ :consumer_secret => 'sxHqc42O0eNU8C2KlVmDB67jsXRftOwLMYrgh6PGM4',
+ :token => @callsign.access_token,
+ :secret => @callsign.access_secret
+ )
+ @client.update(@tweet)
+
+
+ end
+
+ end
+
+ end
+
+ end
+ end
+
+
+ @aprsupdate.published = Time.now()
+ @aprsupdate.save
+
+ render :layout=>false
+
+ end
+
private
@@ -32,7 +32,12 @@ def callsign
#@user = User.find_by_login(@callsign)
# @user = User.find(:first, :conditions => ['login = ?', @callsign])
- @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ # @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ if request.url.index('localhost')
+ @user = User.find(:first, :conditions => ['login LIKE ?', @callsign])
+ else
+ @user = User.find(:first, :conditions => ['login ILIKE ?', @callsign])
+ end
if @user
View
@@ -132,19 +132,20 @@ def full_name
def self.featured
- # LOCALHOST
- # find_options = {
- # :include => :user,
- # :conditions => ["is_active = ? and about_me IS NOT NULL and user_id is not null", true],
- # :order => "RAND()",
- # }
+
+ # LOCALHOST
+ # find_options = {
+ # :include => :user,
+ # :conditions => ["is_active = ? and about_me IS NOT NULL and user_id is not null", true],
+ # :order => "RAND()",
+ # }
- # HEROKU
- find_options = {
- :include => :user,
- :conditions => ["is_active = ? and about_me IS NOT NULL and user_id is not null", true],
- :order => "RANDOM()",
- }
+ # HEROKU
+ find_options = {
+ :include => :user,
+ :conditions => ["is_active = ? and about_me IS NOT NULL and user_id is not null", true],
+ :order => "RANDOM()",
+ }
#find(:first, find_options.merge(:offset => rand( count(find_options) - 1)))
find(:first, find_options.merge(:offset => rand(count(find_options)).floor))
View
@@ -85,7 +85,11 @@ def can_mail? user
# Returns the user or nil.
def self.authenticate(login, password)
# u = find_by_login(login) # need to get the salt
- u = User.find(:first, :conditions => ['login ILIKE ?', login])
+ if request.url.index('localhost')
+ u = User.find(:first, :conditions => ['login LIKE ?', login])
+ else
+ u = User.find(:first, :conditions => ['login ILIKE ?', login])
+ end
u && u.authenticated?(password) ? u : nil
end
@@ -4,11 +4,13 @@ profile ||= @profile
type ||= 'friends'
size ||= 18
-# LOCALHOST
-# list = profile.send(type).find(:all, :limit => size, :order => 'RAND()') rescue []
-# Hereko
-list = profile.send(type).find(:all, :limit => size, :order => 'RANDOM()') rescue []
+if request.url.index('localhost')
+ list = profile.send(type).find(:all, :limit => size, :order => 'RAND()') rescue []
+else
+ list = profile.send(type).find(:all, :limit => size, :order => 'RANDOM()') rescue []
+end
+
total = profile.send(type).count
with_friending ||= false
@@ -0,0 +1 @@
+<%=@aprs%>
View
@@ -167,6 +167,7 @@
map.connect '/companies/:id/edit', :controller => 'companies', :action => 'update'
map.connect '/twitter/deauthorize/:id', :controller => 'profiles', :action => 'deauth'
+ map.connect '/aprs/poll', :controller => 'statuses', :action => 'poll'
# Install the default routes as the lowest priority.
View
@@ -13,6 +13,12 @@ namespace :utils do
@feed = `#{@url}`
end
+
+# APRS.FI APIKEY = 27286.QJTmrxJGMvlNh
+# http://api.aprs.fi/api/get?what=msg&dst=N7ICE&apikey=27286.QJTmrxJGMvlNh&format=json
+# {"command":"get","result":"ok","found":1,"what":"msg","entries":[{"messageid":"19963994","time":"1307195053","srccall":"73S","dst":"N7ICE","message":"N7ICE-test from 73s via 73s.org"}]}
+
+
# rake utils:aprs_feeds
task(:aprs_feeds => :environment) do
@aprsupdate = Aprsupdate.find(:first)
Oops, something went wrong.

0 comments on commit 67ab68f

Please sign in to comment.