Giter Site home page Giter Site logo

umbrella's Introduction

Umbrella

In this project, we'll write a Ruby program that uses the Google Maps API and Dark Sky API to tell the user whether or not they should carry an umbrella with them when they leave home.

Solution

There is a solution in the file called solution.rb.

  • You can run it to see how the program should behave:

    ruby solution.rb
    
  • Before it will work, you need to create two environment variables in your Gitpod dashboard.

    • Read how to create environment variables here.
    • You need to create env vars called GMAPS_KEY and DARK_SKY_KEY. You'll find the values to assign in the assignment in Canvas.
    • When asked for "Organization/Repository", say */*. This will make the env vars available across all of your workspaces.
    • Don't forget to restart your workspace after the variables have been saved
      • In your Gitpod dashboard, find the workspace.
      • Click on the three dots next to its name.
      • Stop.
      • Once it has shut down, Open it again.
  • Then, try running solution.rb and enter some rainy locations — you should be able to find some using this live radar.

  • Don't peek at the solution until you've tried things yourself.

Program outline

Here is a suggested outline for your program:

  • Ask the user for their location.

  • Get and store the user's location.

  • Get the user's latitude and longitude from the Google Maps API.

  • Get the weather at the user's coordinates from the Dark Sky API.

  • Display the current temperature and summary of the weather for the next hour.

  • For each of the next twelve hours, check if the precipitation probability is greater than 10%.

    • If so, print a message saying how many hours from now and what the precipitation probability is.
  • If any of the next twelve hours has a precipitation probability greater than 10%, print "You might want to carry an umbrella!"

    If not, print "You probably won't need an umbrella today."

Useful links

Some handy links:

Useful methods

Most of working with APIs boils down to working with Arrays and Hashes.

You will likely also need to use if statements and loops (most useful programs do).

Here are some less familiar methods that will be useful:

  • URI.open(): The argument to URI.open should be a String containing a URL. The method will then read the page at the provided URL and return it as a Tempfile.

    • In order to use this method, we must require "open-uri".
  • Tempfile#read: If you call .read on an instance of Tempfile, it will return the contents of the file as a String.

  • JSON.parse(): The argument to JSON.parse should be a String containing valid JSON. The method will transform the JSON objects into Ruby objects.

    • In order to use this method, we must require "json".
  • Time.at(): The argument to Time.at should be an Integer representing the Epoch time. The method will transform the Integer into an instance of Time.

    You could also try this online epoch time converter.

  • You can use a Range along with the [] method to access a specific set of elements within an Array:

    array = [8, 3, 1, 19, 23, 3]
    
    p array[2..4] # => [1, 19, 23]

Stretch goal

Use the ascii_charts gem to produce output that includes a chart, like this:

========================================
    Will you need an umbrella today?    
========================================

Where are you?
brooklyn
Checking the weather at Brooklyn....
Your coordinates are 40.6781784, -73.9441579.
It is currently 51.33°F.
Next hour: Possible light rain starting in 25 min.
 
Hours from now vs Precipitation probability
 
80|                                    
75| *                                  
70| *                                  
65| *                                  
60| *                                  
55| *                                  
50| *                                  
45| *                                  
40| *                                  
35| *                                  
30| *                                  
25| *                             *  * 
20| *                          *  *  * 
15| *              *  *  *  *  *  *  * 
10| *           *  *  *  *  *  *  *  * 
 5| *  *  *  *  *  *  *  *  *  *  *  * 
 0+-*--*--*--*--*--*--*--*--*--*--*--*-
    1  2  3  4  5  6  7  8  9 10 11 12 
 
You might want to take an umbrella!

umbrella's People

Contributors

raghubetina avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.