-
Notifications
You must be signed in to change notification settings - Fork 0
/
horostoday.rb
executable file
·89 lines (70 loc) · 2.53 KB
/
horostoday.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env ruby
require_relative 'lib/RuephBase.rb'
require_relative 'lib/Rueph.rb'
require_relative 'lib/horostoday.rb'
require 'time'
require 'sinatra/base'
require 'timezone'
require 'sinatra/cookies'
require 'sanitize'
require 'geocoder'
class HorosTodayServer < Sinatra::Application
#TODO: wheneverize 0 0 * * * * or whatever the range calculation daily
# https://medium.com/@davidjtomczyk/scheduling-jobs-with-whenever-f1fc7b401733
#TODO: https://www.simon-neutert.de/2017/persistend-cookies-with-sinatra/
set :bind, '0.0.0.0'
HorosToday.set_ephe_path('ephe')
daily_hash = {}
get '/' do
tz = request.cookies['tz']
if tz
@tz_offset = Integer(tz || '')
begin
#@tz_offset = Integer(tz || '')
#TODO: Fix ArgumentError raising
rescue ArgumentError
nil
else
if daily_hash[@tz_offset].nil?
if Time.now.utc.day != Time.now.getlocal(@tz_offset*60*60).day
t = [Time.now.utc.year, Time.now.utc.month, Time.now.utc.day - 1, 12]
else
# check if utc.day matches tz_offset + utc.minutes
t = [Time.now.utc.year, Time.now.utc.month, Time.now.utc.day, 12]
end
daily_hash[@tz_offset] = { sun: HorosToday.sign_of(t, HorosToday::SUN),
aspects: HorosToday.get_daily_planet_aspects_exact(HorosToday::MOON, t, @tz_offset) }
daily_hash[@tz_offset][:aspect_list] = []
daily_hash[@tz_offset][:aspects].each do |aspect|
daily_hash[@tz_offset][:aspect_list].append [aspect[0], aspect[1][0]]
end
daily_hash[@tz_offset][:lunar_transit] = HorosToday.moon_void_print(HorosToday.moon_void(daily_hash[@tz_offset][:aspects], t, @tz_offset))
end
end
@daily_hash = daily_hash
@sun = @daily_hash[@tz_offset][:sun]
@aspects = @daily_hash[@tz_offset][:aspects]
@lunar_transit = @daily_hash[@tz_offset][:lunar_transit]
@aspect_list = @daily_hash[@tz_offset][:aspect_list]
else
redirect to('/get_tz')
end
erb :index
end
get '/get_tz' do
erb :get_tz
end
post '/' do
results = Geocoder.search(Sanitize.fragment(params[:geolocation]))
Timezone::Lookup.config(:geonames) do |c|
c.username = 'prkrmcgwn'
end
tz = Timezone.lookup(results.first.coordinates[0], results.first.coordinates[1])
response.set_cookie("tz", {
:value => tz.utc_offset/(60*60),
:max_age => "2592000",
:path => '/'
})
redirect to('/')
end
end