-
Notifications
You must be signed in to change notification settings - Fork 72
Modified meteoservice.rb to parse cities and their indexes from json file #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimKm
wants to merge
2
commits into
aristofun:master
Choose a base branch
from
TimKm:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "Москва" : 37, | ||
| "Пермь" : 59, | ||
| "Санкт-Петербург" : 69, | ||
| "Новосибирск" : 99, | ||
| "Орел" : 31584, | ||
| "Чита" : 121, | ||
| "Братск" : 141, | ||
| "Краснодар" : 199 | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,37 +16,33 @@ | |
|
|
||
| require 'net/http' | ||
| require 'rexml/document' | ||
| require 'json' | ||
|
|
||
| require_relative 'lib/meteoservice_forecast' | ||
| require_relative 'data/cities.json' | ||
|
|
||
| # Словарик городов, собранных с сайта Метеосервиса. Можно написать код, который | ||
| # будет собирать все города и их названия с сайта амтоматически, но мы пока | ||
| # этого делать не будем. При необходимости добавляйте свои города руками. | ||
| CITIES = { | ||
| 37 => 'Москва', | ||
| 69 => 'Санкт-Петербург', | ||
| 99 => 'Новосибирск', | ||
| 59 => 'Пермь', | ||
| 115 => 'Орел', | ||
| 121 => 'Чита', | ||
| 141 => 'Братск', | ||
| 199 => 'Краснодар' | ||
| }.invert.freeze | ||
|
|
||
| # Сделаем массив из наваний городов, взяв ключи массива CITIES | ||
| city_names = CITIES.keys | ||
| # Прочитаем файл с городами и их индексами(https://www.meteoservice.ru/content/export.html) | ||
| # И запишем данные в cities | ||
| file = File.read("#{__dir__}/data/cities.json", encoding: 'utf-8') | ||
| cities = JSON.parse(file) | ||
|
|
||
| # Спрашиваем у пользователя, какой город по порядку ему нужен | ||
| puts 'Погоду для какого города Вы хотите узнать?' | ||
| city_names.each_with_index { |name, index| puts "#{index + 1}: #{name}" } | ||
| city_index = gets.to_i | ||
| unless city_index.between?(1, city_names.size) | ||
| city_index = gets.to_i | ||
| puts "Введите число от 1 до #{city_names.size}" | ||
| cities.each_with_index do |name,index| | ||
| puts "#{index+1}: #{name.first}" | ||
| end | ||
|
|
||
| city_index = gets.chomp.to_i | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No meed for chomp here |
||
| # Пока пользователь не введет число между 1 и 8 (в нашем случае) | ||
| # програма будет уведомлять об не правильном вводе и просить ввести число снова | ||
| until city_index.between?(1, cities.size) | ||
| puts "Неверный выбор!" | ||
| puts "Пожалуйста введите число от 1 до #{cities.size}" | ||
| city_index = gets.chomp.to_i | ||
| end | ||
|
|
||
| # Когда, наконец, получим нуный индекс, достаем city_id | ||
| city_id = CITIES[city_names[city_index - 1]] | ||
| city_id = cities[cities[city_index - 1]] | ||
|
|
||
| # Сформировали адрес запроса | ||
| url = "http://xml.meteoservice.ru/export/gismeteo/point/#{city_id}.xml" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it required?
please inline it for simplicity