Q&A
rubyをつかって、twitterの地震botを作っているのですが、どうにもエラーが出てしまいます
エラーの内容は読み込めてないとわかったのですが、直し方がわかりません。教えてください
コードはこんな感じです
*****の場所は隠してます
ruby
1# encoding: utf-8 2require "open-uri" 3require "uri" 4require "rubygems" 5require "nokogiri" 6require "twitter" 7 8class HttpClient 9 User_Agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" 10 def self.request(url) 11 begin 12 response = open(url, "User-Agent" => User_Agent) 13 doc = Nokogiri::HTML(response) 14 rescue OpenURI::HTTPError => err 15 puts err.message 16 end 17 end 18end 19 20class Parser 21 def self.parse(doc) 22 info = {} 23 doc.css(".yjw_table").first.css("tr").each do |tr| 24 info_name,info_value = tr.text.split("\n") 25 info[info_name] = info_value.strip 26 end 27 return info 28 end 29end 30 31class TwitterClient 32 require 'openssl' 33 # Avoid "SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed" 34 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 35 36 CONSUMER_KEY = '**********' 37 CONSUMER_SECRET = '********' 38 OAUTH_TOKEN = '*******' 39 OAUTH_TOKEN_SECRET = '*******' 40 41 def self.tweet(message) 42 Twitter::Client.new( 43 :consumer_key => CONSUMER_KEY, 44 :consumer_secret => CONSUMER_SECRET, 45 :oauth_token => OAUTH_TOKEN, 46 :oauth_token_secret => OAUTH_TOKEN_SECRET 47 ).update(message) 48 end 49end 50 51begin 52 info = Parser::parse(HttpClient::request("http://typhoon.yahoo.co.jp/weather/jp/earthquake/")) 53 54 prev_datetime = nil 55 56 if (File.exists?("earthquake.log")) 57 File.open("earthquake.log", "r") do |file| 58 prev_datetime = file.read 59 file.close 60 end 61 end 62 63 exit if prev_datetime == info["発生時刻"] 64 65 TwitterClient::tweet( 66 info["発生時刻"] + "、地震が発生しました。震源地は" + info["震源地"] + "、マグニチュード" + info["マグニチュード"] + "です。" + info["情報"] 67 ) 68 69 File.open("earthquake.log", "w") do |file| 70 file.write(info["発生時刻"]) 71 file.close 72 end 73rescue 74 puts $! 75end 76 77{ 78 "url": "https://replit.com:/*******?s=app", 79 "duration": "30 second", 80 "method": "https://kron.4ty2.fun/new", 81 "payload":{ 82 "username": "******", 83 "ID": "******" 84 } 85}
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/01/20 01:07
2023/01/20 01:10
2023/01/20 01:35
2023/01/20 04:33