hacker_weather 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36f417e9b11f533b13b5bcf1a654d2f9894cc60427984ad4460b097161997d21
4
+ data.tar.gz: 2dbd16f97a2710734b01564ecdcb55393b3353e3d31cfcc135ed1155e27b4f07
5
+ SHA512:
6
+ metadata.gz: 530b5cf82fe613b8811902762c6534a874f8e0e0d709ff5aee9499e2cb78cc57f2e3a8ff97f51a28bd13ee36ef172580cfe5b8ce4bbd83e03b36eef965dd9e84
7
+ data.tar.gz: f506e74e12a82102508948add9b4395da358d73c23d5e70d1d292fee9c8d9c90aa8ddf5a531dd3d0756f380ee58f384c7a65533752363a0bd4d1b1198d9cc385
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in hacker_weather.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hacker_weather (0.1.0)
5
+ nokogiri (~> 1.8.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ mini_portile2 (2.3.0)
11
+ minitest (5.14.4)
12
+ nokogiri (1.8.5)
13
+ mini_portile2 (~> 2.3.0)
14
+ rake (13.0.3)
15
+
16
+ PLATFORMS
17
+ x86_64-darwin-19
18
+
19
+ DEPENDENCIES
20
+ hacker_weather!
21
+ minitest (~> 5.0)
22
+ rake (~> 13.0)
23
+
24
+ BUNDLED WITH
25
+ 2.2.16
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # HackerWeather
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/hacker_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 'hacker_weather'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hacker_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 test` 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 the created tag, 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]/hacker_weather.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hacker_weather"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/hw ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hacker_weather'
4
+
5
+ HackerWeather.get_weather
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hacker_weather/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hacker_weather"
7
+ spec.version = HackerWeather::VERSION
8
+ spec.authors = ["Gulchaman Mammadova"]
9
+ spec.email = ["gulchaman.mammadova@gmail.com"]
10
+
11
+ spec.summary = "Get weather temperature for your city in the terminal."
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/gmammadova/hacker_weather"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency "nokogiri", "~> 1.8.5"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'json'
5
+ require_relative "hacker_weather/version"
6
+
7
+ module HackerWeather
8
+
9
+ def self.get_weather
10
+ province = ARGV[0]
11
+ city = ARGV[1]
12
+
13
+ if province == nil || city == nil
14
+ puts "The program requires province and city name. For example: hw ontario ottawa"
15
+ exit
16
+ end
17
+
18
+ url = "https://www.theweathernetwork.com/ca/weather/#{province}/#{city}"
19
+
20
+ puts "Fetching placecode for the given city and province"
21
+
22
+ response_body = URI.open(url).read
23
+
24
+ # parsing HTML response_body
25
+ document = Nokogiri::HTML(response_body)
26
+ script_tags = document.search("script")
27
+ script_tag_with_placecode = script_tags.find { |script_tag| script_tag.text.match(/var _config/) }
28
+ parsed_script_content = script_tag_with_placecode.text.match(/\"placecode\":\"([a-z0-9]+)\"/)
29
+ placecode = parsed_script_content[1]
30
+
31
+ puts "Placecode corresponding to #{province}/#{city} is #{placecode}"
32
+
33
+ puts "Fetching temperature"
34
+ url_temperature = "https://weatherapi.pelmorex.com/api/v1/observation/placecode/#{placecode}"
35
+ response_body_temperature = URI.open(url_temperature).read
36
+
37
+ parsed_body = JSON.parse(response_body_temperature)
38
+ temperature = parsed_body["observation"]["temperature"]
39
+
40
+ puts "Temperature for #{province}/#{city} is #{temperature} degrees Celsius"
41
+ puts "\nThis program is for learning purposes and the data is pulled from #{url}"
42
+ end
43
+
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HackerWeather
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hacker_weather
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gulchaman Mammadova
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.5
27
+ description: Get weather temperature for your city in the terminal.
28
+ email:
29
+ - gulchaman.mammadova@gmail.com
30
+ executables:
31
+ - hw
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - exe/hw
43
+ - hacker_weather.gemspec
44
+ - lib/hacker_weather.rb
45
+ - lib/hacker_weather/version.rb
46
+ homepage: https://github.com/gmammadova/hacker_weather
47
+ licenses: []
48
+ metadata:
49
+ allowed_push_host: https://rubygems.org
50
+ homepage_uri: https://github.com/gmammadova/hacker_weather
51
+ source_code_uri: https://github.com/gmammadova/hacker_weather
52
+ changelog_uri: https://github.com/gmammadova/hacker_weather
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.2.3
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Get weather temperature for your city in the terminal.
72
+ test_files: []