Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.