-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
executable file
·50 lines (37 loc) · 1.16 KB
/
server.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
#!/usr/bin/env ruby
lib_dir = File.join(File.dirname(__FILE__), 'lib')
$LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
require 'newsbot'
require 'sinatra'
configure do
mime_type :text, 'text/text'
end
set :logging, true
post '/run' do
content_type :text
output = ENV['newsbot_output'] || "./tmp/output"
repo = ENV['newsbot_repo'] || "./tmp/repository"
url = ENV['newsbot_repo_url'] || "https://github.com/Hunter-Dolan/GitTest.git"
key = ENV['newsbot_key']
s3_access_key = ENV["s3_access_key"]
s3_secret_key = ENV["s3_secret_key"]
s3_bucket = ENV["s3_bucket"]
if(key == params["key"])
Newsbot::Manager.clean_output output
puts "[Cleaned Repo]"
if File.directory?(repo)
Newsbot::Repo.pull repo
puts "[Pulled Repo]"
else
Newsbot::Repo.clone repo, url
puts "[Cloned Repo]"
end
Newsbot::Manager.generate_posts repo, output
puts "[Generated Posts]"
Newsbot::Storage.new.sync(output, s3_access_key, s3_secret_key, s3_bucket) if s3_access_key && s3_secret_key && s3_bucket
puts "[Uploaded to S3]"
return "Done"
else
return "Invalid Key"
end
end