/
Rakefile
177 lines (118 loc) · 3.16 KB
/
Rakefile
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# frozen_string_literal: true
require './bullish.rb'
require './services/news/crawler'
require './services/twitter'
task default: %w[test]
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = 'test/**/*_test.rb'
t.warning = false
end
task :send_free_edition do
day = ARGV[1]
send_email(Bullish.free_edition, day)
exit
end
task :send_morning_edition do
day = ARGV[1]
send_email(Bullish.morning_edition, day)
exit
end
task :send_afternoon_edition do
day = ARGV[1]
send_email(Bullish.afternoon_edition, day)
exit
end
task :preview_free_email do
day = ARGV[1]
bullish = Bullish.free_edition
preview_email(bullish, day)
exit
end
task :preview_free_email_template do
day = ARGV[1]
bullish = Bullish.free_edition
preview_email_template(bullish, day)
exit
end
task :preview_morning_email do
day = ARGV[1]
bullish = Bullish.morning_edition
preview_email(bullish, day)
exit
end
task :preview_morning_email_template do
day = ARGV[1]
bullish = Bullish.morning_edition
preview_email_template(bullish, day)
exit
end
task :preview_afternoon_email do
day = ARGV[1]
bullish = Bullish.afternoon_edition
preview_email(bullish, day)
exit
end
task :preview_afternoon_email_template do
day = ARGV[1]
bullish = Bullish.afternoon_edition
preview_email_template(bullish, day)
exit
end
task :preview_all do
Editions::Edition::DAY_ELEMENTS.each do |day, _value|
puts '- ' + day.to_s + ' free'
free = Bullish.free_edition
free.edition.day_of_the_week = day
free.edition.save(day.to_s + '-free ' + free.edition.subject)
puts '- ' + day.to_s + ' morning'
morning = Bullish.morning_edition
morning.edition.day_of_the_week = day
morning.edition.save(day.to_s + '-morning ' + morning.edition.subject)
puts '- ' + day.to_s + ' afternoon'
afternoon = Bullish.afternoon_edition
afternoon.edition.day_of_the_week = day
afternoon.edition.save(day.to_s + '-afternoon ' + afternoon.edition.subject)
end
end
task :build_archive do
archive = Services::Archive.new
archive.build_index
archive.build_directory # TODO: can be optimized to run once a month
end
task :update_news do
# TODO: temp run separately when general news
Services::News::DB.reset
stock_news = Services::Trending.new.stocks.map do |stock|
Services::News::Crawler.stock(stock.symbol)
end.flatten.compact
market_news = Services::News::Crawler.reuters
all_news = stock_news + market_news
Services::News::DB.save(items: all_news) if all_news.any?
end
task :news do
pp Services::News::DB.all.collect(&:headline)
end
task :reset_news do
Services::News::DB.new.reset
end
task :prepare_tweets do
Services::Twitter.reset_tweets
twitter = Services::Twitter.new
Services::Trending.new.stocks.each do |stock|
twitter.add_tweet(stock)
end
twitter.save_tweets
end
def send_email(bullish, day = nil)
bullish.edition.day_of_the_week = day if day
bullish.post
end
def preview_email(bullish, day = nil)
bullish.edition.day_of_the_week = day if day
bullish.save
end
def preview_email_template(bullish, day = nil)
bullish.edition.day_of_the_week = day if day
bullish.save_template
end