tell_me_the_weather 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/tell_me_the_weather +34 -0
- data/lib/tell_me_the_weather.rb +34 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed8a33b20ac291d877044b8bad3437437b9ff649
|
4
|
+
data.tar.gz: e11c8b1abffe11206ba5a7b660eb9ae75e74871e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40e8b4ef0f82448403b1e8a947a0cc57eb7df1118fa9a49483b457a64f6f9d76bd477e34e13731305337e8f763090b6a99b3ee9cc3f6a1399e71096b7caab8b0
|
7
|
+
data.tar.gz: 725140fb943ab09cd11520538a04585849001aa4664fb7b8b4d68ab09b003019c8938f7de0c93276410c72bc79a7485eaae79e6288740de7430e2a4e1afd2862
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'festivaltts4r'
|
3
|
+
require 'curb'
|
4
|
+
require 'json'
|
5
|
+
require 'ruby-units'
|
6
|
+
require 'open-uri'
|
7
|
+
|
8
|
+
class Weather
|
9
|
+
|
10
|
+
# Constructor is going to find zip code by looking up public IP address.
|
11
|
+
def initialize
|
12
|
+
# Need to rescue in case the internet connection doesn't work
|
13
|
+
begin
|
14
|
+
@coordinates = JSON.parse(open("http://ip-api.com/json/?fields=lat,lon").read)
|
15
|
+
if @coordinates['lat'].nil? or @coordinates['lon'].nil?
|
16
|
+
p "Sorry, I don't know where you are"
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
rescue
|
20
|
+
p "Something went wrong, and you're likely not connected to the internet. Please make sure you're connected and try again."
|
21
|
+
p "Exiting..."
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_the_weather
|
27
|
+
weather_data = JSON.parse(Curl.get("api.openweathermap.org/data/2.5/weather?lat=#{@coordinates['lat']}&lon=#{@coordinates['lon']}&APPID=0fc1d8810cd59b15060edc06d5fd58c8").body_str)
|
28
|
+
# Get the temperature and slice off the ending part of the string that gets returned by ruby units.
|
29
|
+
temp_in_farenheit = Unit("#{weather_data["main"]["temp"]} tempK").convert_to("tempF").to_s[0..-7].to_f.round
|
30
|
+
"It's currently #{temp_in_farenheit} degrees in #{weather_data["name"]}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Weather.new.get_the_weather.to_speech
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'festivaltts4r'
|
3
|
+
require 'curb'
|
4
|
+
require 'json'
|
5
|
+
require 'ruby-units'
|
6
|
+
require 'open-uri'
|
7
|
+
|
8
|
+
class Weather
|
9
|
+
|
10
|
+
# Constructor is going to find zip code by looking up public IP address.
|
11
|
+
def initialize
|
12
|
+
# Need to rescue in case the internet connection doesn't work
|
13
|
+
begin
|
14
|
+
@coordinates = JSON.parse(open("http://ip-api.com/json/?fields=lat,lon").read)
|
15
|
+
if @coordinates['lat'].nil? or @coordinates['lon'].nil?
|
16
|
+
p "Sorry, I don't know where you are"
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
rescue
|
20
|
+
p "Something went wrong, and you're likely not connected to the internet. Please make sure you're connected and try again."
|
21
|
+
p "Exiting..."
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_the_weather
|
27
|
+
weather_data = JSON.parse(Curl.get("api.openweathermap.org/data/2.5/weather?lat=#{@coordinates['lat']}&lon=#{@coordinates['lon']}&APPID=0fc1d8810cd59b15060edc06d5fd58c8").body_str)
|
28
|
+
# Get the temperature and slice off the ending part of the string that gets returned by ruby units.
|
29
|
+
temp_in_farenheit = Unit("#{weather_data["main"]["temp"]} tempK").convert_to("tempF").to_s[0..-7].to_f.round
|
30
|
+
"It's currently #{temp_in_farenheit} degrees in #{weather_data["name"]}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Weather.new.get_the_weather.to_speech
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tell_me_the_weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gr1zzly_be4r
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Type the command and it will tell you the weather
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- tell_me_the_weather
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/tell_me_the_weather
|
21
|
+
- lib/tell_me_the_weather.rb
|
22
|
+
homepage: https://github.com/gr1zzly-be4r/tell-me-the-weather
|
23
|
+
licenses:
|
24
|
+
- GPL
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: The weather speaks to you
|
46
|
+
test_files: []
|