Created
November 19, 2018 12:05
-
-
Save glurp/5c0635c85fe9d3ba65e67181853bc644 to your computer and use it in GitHub Desktop.
blague check norris , periodique
This file contains hidden or 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 'ssl_certificate' | |
require 'open-uri' | |
require 'json' | |
require 'nokogiri' | |
#require "win32/sapi5" | |
#include Win32 | |
#$audio = SpVoice.new | |
#$audio.Rate=1 | |
#$audio.Volume=100 | |
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
$time=File.mtime(__FILE__) | |
$periode= $periode= (ARGV.first == "-p") ? ( ARGV.shift ;ARGV.shift.to_i*60) : 15 | |
$title=ARGV.join(" ") | |
$title='Chuck Norris' if $title.size==0 | |
# [{ "id":"144512","fact":"Quand Chuck Norris ....","date":"1504726103","vote":"348","points":"1095"},....] | |
def speak(txt) | |
system("voice.exe","-v","100","-r","1",txt) # https://www.elifulkerson.com/projects/commandline-text-to-speech.php | |
end | |
def getblague() | |
json=nil | |
open("https://www.chucknorrisfacts.fr/api/get?data=type:txt;nb:99") {|f| json=f.read} | |
return '' if ! json || json.size<10 | |
txt=JSON.parse(json).select {|h| h['points'].to_i>1 && h['fact'].size<300}.shuffle.first['fact'] | |
Nokogiri::HTML.parse(txt).text.gsub(/chuck norris/i,$title) | |
end | |
def messages(txt) | |
puts "say #{txt}" | |
speak(Time.now.strftime("#{txt} %Hh%M")) | |
speak(getblague()) | |
end | |
puts "Periode => #{$periode} seconds" | |
messages("il est") | |
loop { | |
while (Time.now.to_i % ($periode) !=0) | |
sleep(1) | |
( $audio.Speak("Regis m'a tuer, baïbaï !") ; exit(0)) if $time!=File.mtime(__FILE__) | |
end | |
messages("Il est exactement,") | |
sleep(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment