Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created August 24, 2019 03:17
Show Gist options
  • Save mrkn/4b2fd069c0583af94ed4416671778ccc to your computer and use it in GitHub Desktop.
Save mrkn/4b2fd069c0583af94ed4416671778ccc to your computer and use it in GitHub Desktop.
The lambda function of daily_prime_check
require 'json'
require 'prime'
require 'net/http'
require 'uri'
SLACK_URL = 'https://hooks.slack.com/services/....'
def post_to_slack(url, message)
uri = URI.parse(url)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.post(uri.path, JSON.generate(message), {'Content-Type' => 'application/json'})
end
response.value
end
def lambda_handler(event:, context:)
today = Time.now.strftime("%Y%m%d")
body = ""
while today != ""
body << "#{today} => #{today.to_i.prime? ? '素数' : '合成数'}\n"
today = today[1..-1]
end
post_to_slack(SLACK_URL, {"text" => body})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment