Created
July 23, 2013 11:49
-
-
Save octplane/6061771 to your computer and use it in GitHub Desktop.
Les sources de FotonautsBot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
require 'chatterbot' | |
require 'htmlentities' | |
BASE_URL = "http://meteo.orange.fr/Php/getPrevPluies.php" | |
ARG = "code=0751080" | |
def get_weather | |
agent = Mechanize.new | |
params = {'code' => '0751080'} | |
# ajax_headers = { 'X-Requested-With' => 'XMLHttpRequest', 'Content-Type' => 'application/json; charset=utf-8', 'Accept' => 'application/json, text/javascript, */*'} | |
response = agent.post( BASE_URL, params ) | |
data = response.body.split(/\n/)[0].gsub(/.*oStore.rainSliderParams.aDatas = /, '') | |
forecast = eval(data) | |
coder = HTMLEntities.new | |
rain_data = {} | |
forecast.each do |data| | |
rain_data[data[0]] = coder.decode(data[1]) | |
end | |
return rain_data | |
end | |
SLEEP=300 | |
current_weather=nil | |
require 'chatterbot/dsl' | |
while true do | |
forecast = get_weather() | |
next_date = forecast.keys()[0] | |
forecast_weather = forecast[next_date] | |
if forecast_weather != current_weather | |
puts "Dans le VIIIe, #{forecast_weather} a partir de #{next_date}" | |
tweet "Dans le VIIIe, #{forecast_weather} a partir de #{next_date}" | |
end | |
sleep(SLEEP) | |
current_weather = forecast_weather | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment