This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.rb
87 lines (68 loc) · 2.12 KB
/
orders.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
before do
@db = SQLite3::Database.new './curry_house.sqlite'
@caught_tweets = @db.execute('SELECT * FROM tweets')
@valid_city = Array.new(@caught_tweets.size,true)
end
get '/orders' do
redirect '/' if !session[:admin]
@sheff_orders = true
@birm_orders = true
@too_many_requests = false
begin
new_orders = search_timeline
new_orders.each do |tweet|
if tweet.text.include?('order')
process_order tweet
elsif tweet.text.include?('cancel')
process_cancellation tweet
end
end
rescue Twitter::Error::TooManyRequests => err
@limit = err.rate_limit.reset_in
@too_many_requests = true
puts "TooManyRequests, try again in #{err.rate_limit.reset_in} seconds"
end
@caught_tweets = @db.execute('SELECT * FROM tweets')
@valid_city = Array.new(@caught_tweets.size,true)
erb :orders
end
post '/change_status' do
@sheff_orders = true
@birm_orders = true
for i in 1..@caught_tweets.size do
if params["status#{i}"]=="on"
@db.execute('UPDATE tweets SET status = ? WHERE id = ?',[params[:change_to],@caught_tweets[i-1][0]])
@caught_tweets[i-1][3] = params[:change_to]
puts @caught_tweets[i-1][3]
tweet_status_change(@caught_tweets[i-1])
end
end
erb :orders
end
get '/sheffield_orders' do
redirect '/' if !session[:admin]
@sheff_orders = true
@birm_orders = false
@caught_tweets = @db.execute('SELECT * FROM tweets WHERE city = "sheffield"')
erb :orders
end
get '/birmingham_orders' do
redirect '/' if !session[:admin]
@sheff_orders = false
@birm_orders = true
@caught_tweets = @db.execute('SELECT * FROM tweets WHERE city = "birmingham"')
erb :orders
end
get '/customer_orders' do
redirect '/' if (!session[:logged_in] ||session[:admin])
erb :customer_orders
end
post '/cancel_orders' do
for i in 1..@caught_tweets.size do
if params["status#{i}"]=="on"
@db.execute('UPDATE tweets SET status = ? WHERE id = ?',['Canceled',@caught_tweets[i-1][0]])
@caught_tweets[i-1][3] = 'Canceled'
end
end
erb :customer_orders
end