damn-weather 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/damn-weather.gemspec +26 -0
- data/lib/damn_weather.rb +26 -0
- data/lib/damn_weather/emoji.rb +69 -0
- data/lib/damn_weather/forecast.rb +41 -0
- data/lib/damn_weather/now.rb +38 -0
- data/lib/damn_weather/version.rb +3 -0
- data/lib/damn_weather/weather.rb +35 -0
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa562cdfb03616d6929aa93eb30ba8b2c122af4d
|
4
|
+
data.tar.gz: a1d8fb05fe98ce17245c8a84d67af93ba93aedc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0675ec78084a919081d0b3f3c3bdfda0deb26261803e2e3e61ea17cd5388c31a46f2bc74c1eb168701f49f750d72dc2e724c867aa86de92c5a80261c24369d3e
|
7
|
+
data.tar.gz: 65b61b8d6f0c2e757d4120ef5e30538affe2bfdca90639a5087d9e4f1c62b3858e906639defe5e9e84b5dbffd5da2eb4f07cc0521cf5866aed0f20875e8a4cf9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# DamnWeather
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/damn_weather`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'damn_weather'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install damn_weather
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/damn_weather. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'damn_weather/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "damn-weather"
|
8
|
+
spec.version = DamnWeather::VERSION
|
9
|
+
spec.authors = ["Justyna Rachowicz"]
|
10
|
+
spec.email = ["mrowa44@gmail.com"]
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.summary = %q{Get some damn emoji weather for your terminal!}
|
14
|
+
spec.homepage = "https://github.com/mrowa44/damn-weather"
|
15
|
+
|
16
|
+
spec.bindir = "bin"
|
17
|
+
spec.executables << "damn-weather"
|
18
|
+
spec.files = `git ls-files`.split("\n")
|
19
|
+
spec.require_paths = ["lib", "bin"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency "mm_geoip", "~> 0.1.1"
|
24
|
+
spec.add_dependency "slop", "~> 4.2"
|
25
|
+
spec.add_dependency "terminal-table", "~> 1.5"
|
26
|
+
end
|
data/lib/damn_weather.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'mm_geoip'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'zlib'
|
5
|
+
require 'terminal-table'
|
6
|
+
require "damn_weather/version"
|
7
|
+
require "damn_weather/emoji"
|
8
|
+
require 'damn_weather/weather'
|
9
|
+
require 'damn_weather/now'
|
10
|
+
require 'damn_weather/forecast'
|
11
|
+
|
12
|
+
module DamnWeather
|
13
|
+
|
14
|
+
def db_file_check
|
15
|
+
gem_root = Gem::Specification.find_by_name('mm_geoip').gem_dir
|
16
|
+
db_file = "#{gem_root}/data/GeoLiteCity.dat"
|
17
|
+
unless File.exist?(db_file)
|
18
|
+
puts "Downloading database file... (This may take a while)"
|
19
|
+
open(db_file, 'w') do |local_file|
|
20
|
+
open('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz') do |remote_file|
|
21
|
+
local_file.write(Zlib::GzipReader.new(remote_file).read)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Emoji
|
2
|
+
def heavy_rain
|
3
|
+
["\xF0\x9F\x92\xA6", # multiple drops
|
4
|
+
"\xE2\x98\x94", # umbrella with drops
|
5
|
+
"\xF0\x9F\x98\x9E", # disappointed face
|
6
|
+
"\xF0\x9F\x98\xBF", # crying cat
|
7
|
+
"\xF0\x9F\x92\xA7" # droplet
|
8
|
+
]
|
9
|
+
end
|
10
|
+
|
11
|
+
def light_rain
|
12
|
+
["\xF0\x9F\x92\xA7", # droplet
|
13
|
+
"\xF0\x9F\x98\x92", # unamused face
|
14
|
+
"\xE2\x9B\x85" # sun behind cloud
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def snow
|
19
|
+
["\xE2\x9B\x84", # snowman
|
20
|
+
"\xF0\x9F\x8F\x82", # snowboarder
|
21
|
+
"\xE2\x9D\x84" # snowflake
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def fog_wind
|
26
|
+
["\xF0\x9F\x8C\x81", # foggy
|
27
|
+
"\xF0\x9F\x8D\x83", # leaf fluttering in wind
|
28
|
+
"\xF0\x9F\x92\xA8" # dash symbol
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def extreme
|
33
|
+
["\xF0\x9F\x8C\x80", # cyclone
|
34
|
+
"\xF0\x9F\x92\xA2", # anger symbol
|
35
|
+
"\xF0\x9F\x98\xB1", # face screaming in fear
|
36
|
+
"\xF0\x9F\x8C\x8B", # volcano
|
37
|
+
"\xF0\x9F\x94\xA5" # fire
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
def sunny
|
42
|
+
["\xF0\x9F\x98\x8E", # sunglasses
|
43
|
+
"\xF0\x9F\x94\x86", # high brightness symbol
|
44
|
+
"\xF0\x9F\x91\x8D" # thumbs up
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
def partly_cloudy
|
49
|
+
["\xE2\x9B\x85", # sun behind cloud
|
50
|
+
"\xF0\x9F\x98\x92", # unamused face
|
51
|
+
"\xF0\x9F\x8C\x82" # closed umbrella
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def cloudy
|
56
|
+
["\xE2\x9B\x85", # sun behind cloud
|
57
|
+
"\xF0\x9F\x8C\x82", # closed umbrella
|
58
|
+
"\xF0\x9F\x92\xAD" # thought balloon
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
def thunder
|
63
|
+
["\xF0\x9F\x98\xA8", # fearful face
|
64
|
+
"\xF0\x9F\x99\x88", # monkey with hands on face
|
65
|
+
"\xE2\x98\x94", # umbrella with drops
|
66
|
+
"\xE2\x9A\xA1" # high voltage sigh
|
67
|
+
]
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module DamnWeather
|
2
|
+
class Forecast
|
3
|
+
include Weather
|
4
|
+
|
5
|
+
def initialize(days)
|
6
|
+
@count = days * 8
|
7
|
+
end
|
8
|
+
|
9
|
+
def weather
|
10
|
+
data = open("http://api.openweathermap.org/data/2.5/forecast?lat=#{geo.lat}&lon=#{geo.lng}&cnt=#{@count}&units=metric&APPID=#{APP_ID}").read
|
11
|
+
JSON.parse(data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def city
|
15
|
+
weather['city']['name']
|
16
|
+
end
|
17
|
+
|
18
|
+
def country
|
19
|
+
weather['city']['country']
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_table(data)
|
23
|
+
rows = []
|
24
|
+
data.each do |k|
|
25
|
+
date = Date.parse(k['dt_txt']).strftime(format='%d-%m-%y')
|
26
|
+
time = k['dt_txt'][11...-3]
|
27
|
+
temp = k['main']['temp'].to_i
|
28
|
+
icons = weather_icons(k['weather'].first['id']).join(' ')
|
29
|
+
description = k['weather'].first['description']
|
30
|
+
rows << [icons, "#{temp}\u00B0C", description, time, date]
|
31
|
+
end
|
32
|
+
puts Terminal::Table.new(:title => "Forecast for #{city} (#{country})", :rows => rows, :style => { :width => 80 })
|
33
|
+
end
|
34
|
+
|
35
|
+
def info
|
36
|
+
weather.each do |key, response|
|
37
|
+
build_table(response) if key == 'list'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DamnWeather
|
2
|
+
class Now
|
3
|
+
include Weather
|
4
|
+
|
5
|
+
def weather
|
6
|
+
data = open("http://api.openweathermap.org/data/2.5/weather?lat=#{geo.lat}&lon=#{geo.lng}&units=metric&APPID=#{APP_ID}").read
|
7
|
+
JSON.parse(data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
weather['weather'].first['id']
|
12
|
+
end
|
13
|
+
|
14
|
+
def temp
|
15
|
+
weather['main']['temp'].to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
weather['weather'].first['description']
|
20
|
+
end
|
21
|
+
|
22
|
+
def country
|
23
|
+
weather['sys']['country']
|
24
|
+
end
|
25
|
+
|
26
|
+
def city
|
27
|
+
weather['name']
|
28
|
+
end
|
29
|
+
|
30
|
+
def date
|
31
|
+
DateTime.now.strftime(format='%d-%m-%y')
|
32
|
+
end
|
33
|
+
|
34
|
+
def info
|
35
|
+
puts "#{weather_icons(id).join(' ')} #{description}, #{temp}\u00B0C in #{city} (#{country}) on #{date}."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DamnWeather
|
2
|
+
module Weather
|
3
|
+
include Emoji
|
4
|
+
APP_ID = '7dd66fce2c3028c4b1c55d3781d707be'
|
5
|
+
|
6
|
+
# Weather codes can be found here: http://bugs.openweathermap.org/projects/api/wiki/Weather_Condition_Codes
|
7
|
+
def weather_icons(id, num = 3)
|
8
|
+
case id
|
9
|
+
when (312..314), 321, (502..504), 511, (520..522), 531, 906
|
10
|
+
heavy_rain.sample(num)
|
11
|
+
when (300..311), 500, 501
|
12
|
+
light_rain.sample(num)
|
13
|
+
when (600..602), 611, 612, 615, 616, (620..622), 903
|
14
|
+
snow.sample(num)
|
15
|
+
when 701, 711, 721, 731, 741, 751, 761, 905, (952..958)
|
16
|
+
fog_wind.sample(num)
|
17
|
+
when 762, 771, 781, (900..902), 962
|
18
|
+
extreme.sample(num)
|
19
|
+
when 800, 801, 904, 951
|
20
|
+
sunny.sample(num)
|
21
|
+
when 802, 803, 950
|
22
|
+
partly_cloudy.sample(num)
|
23
|
+
when 804
|
24
|
+
cloudy.sample(num)
|
25
|
+
when (200..202), (210..212), 221, (230..232), (959..961)
|
26
|
+
thunder.sample(num)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def geo
|
31
|
+
current_ip = open('http://ipecho.net/plain').read
|
32
|
+
MMGeoip.new(ip: current_ip)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: damn-weather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justyna Rachowicz
|
@@ -88,7 +88,18 @@ executables:
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
91
95
|
- bin/damn-weather
|
96
|
+
- damn-weather.gemspec
|
97
|
+
- lib/damn_weather.rb
|
98
|
+
- lib/damn_weather/emoji.rb
|
99
|
+
- lib/damn_weather/forecast.rb
|
100
|
+
- lib/damn_weather/now.rb
|
101
|
+
- lib/damn_weather/version.rb
|
102
|
+
- lib/damn_weather/weather.rb
|
92
103
|
homepage: https://github.com/mrowa44/damn-weather
|
93
104
|
licenses:
|
94
105
|
- MIT
|