-
Notifications
You must be signed in to change notification settings - Fork 0
/
travel_advisory.rb
99 lines (69 loc) · 2.65 KB
/
travel_advisory.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
90
91
92
93
94
95
96
97
98
99
require 'httparty'
# require 'pp'
require 'redis'
require 'json'
require 'sinatra'
require 'twilio-ruby'
require 'xmlsimple'
redis = Redis.new(url: ENV['REDIS_URL'])
########## SEED SCRIPT ##########################################################################
response_body = HTTParty.get('https://travel.state.gov/_res/rss/TAsTWs.xml').body
hash = XmlSimple.xml_in(response_body.to_s)
res = hash.values[2].first['item'].first['title'].first.split(" - ")
# redis.set("level 4", [])
hash.values[2].first['item'].each do |el|
res = el['title'].first.split(" - ")
# if res[1].include?('Level 4')
# old = redis.get("level 4")
# redis.set("level 4", old + [res[0]])
# end
res_hash = { "title" => res[1], "pubDate" => el['pubDate'].first, "link" => el['link'].first }.to_json
redis.set(res[0].downcase.strip, res_hash)
end
# blah = JSON.parse(redis.get('bhutan'))
# pp JSON.parse(redis.get('italy'))
# pp "#{blah['title']} #{blah['link']}"
# pp hash.values[2].first['item']
########## UPDATE SCRIPT ##########################################################################
# response_body = HTTParty.get('https://travel.state.gov/_res/rss/TAsTWs.xml').body
# hash = XmlSimple.xml_in(response_body.to_s)
# hash.values[2].first['item'].each do |el|
# res = el['title'].first.split(" - ")
# unless redis.get(res[0]).nil?
# value = JSON.parse(redis.get(res[0]))
# if res[1] != value
# end
# end
######### SEND A TEXT MESSAGE ##########################################################################
# account_sid = 'AC7cc8d97bd45ff0bebd419878b45ab98f'
# auth_token = ENV['TWILIO_AUTH_TOKEN']
# client = Twilio::REST::Client.new(account_sid, auth_token)
# from = '+12059004164' # Your Twilio number
# to = '+19896000145' # Your mobile phone number
# client.messages.create(
# from: from,
# to: to,
# body: "Respond with a country name, first letter capitalized"
# )
# puts JSON.parse(redis.get('asdf'))
########## WEBHOOK #########################################################################################
post '/sms-quickstart' do
twiml = Twilio::TwiML::MessagingResponse.new do |r|
input = params['Body'].downcase.strip
puts input
message = "No information for #{input}"
unless redis.get(input).nil?
value = JSON.parse(redis.get(input))
message = "#{value['title']}\n\n#{value['link']}"
end
r.message(body: message)
end
twiml.to_s
end
# 1. script to seed cache
# 2.
# a. cron job to update cache
# b. text me when update occurs
# 3. be able to text name of a country and get back full report
# 4. be able to get an update of what's changed in the past week/month
# 5. allow people to subscribe to updates