-
Notifications
You must be signed in to change notification settings - Fork 1
/
myapp.rb
62 lines (58 loc) · 1.67 KB
/
myapp.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
require 'rubygems'
require 'twilio-ruby'
require 'sinatra'
require './translate.rb'
require '../account_info'
include AccountInfo
translated = ""
set :bind, '0.0.0.0'
set :port, '8080'
get '/' do
message = params[:Body]
senderState = params[:FromState]
sender = params[:From]
myNumber = params[:To]
sCountry = params[:FromCountry] #Sender Country
#begin stackoverflow code
original_file = './web_log'
new_file = original_file + '.new'
if !File.exist?(original_file)
File.open(original_file, 'w')
end
File.open(new_file, 'w') do |fo|
currTime = `date`
fo.puts "From: #{senderState}\n"
fo.puts "Time: #{currTime}"
fo.puts "Message: #{message}\n"
currTime = `date`
fo.puts "\nTo: #{senderState}\n"
fo.puts "Time: #{currTime}"
translated = translate(message)
fo.puts "Message: #{translated}"
File.foreach(original_file) do |li|
fo.puts li
end
File.rename(original_file, (original_file + '.old'))
File.rename(new_file, original_file)
if sCountry == "CA"
File.open('./counter') do |i|
@client = Twilio::REST::Client.new AccountInfo::SID, AccountInfo::TOKEN
currline = i.readline
puts "http://verydoge.org/dogepics/doge#{(currline.chomp.to_i)-1}.jpg"
message = @client.account.messages.create(:body => "",
:to => sender,
:from => myNumber,
:media_url => "http://verydoge.org/dogepics/doge#{(currline.chomp.to_i)-1}.jpg")
puts message.to
end
else
File.open('./counter') do |i|
twiml = Twilio::TwiML::Response.new do |r|
#r.Message translated
r.Message "#{translated}\nhttp://verydoge.org/dogepics/doge#{(i.readline.chomp.to_i)-1}.jpg"
end
twiml.text
end
end
end
end