Sponsored Content
Full Discussion: Java Wunderground
Top Forums Programming Java Wunderground Post 302931966 by totoro125 on Saturday 17th of January 2015 09:09:43 AM
Old 01-17-2015
Java Wunderground

I am not sure if anyone here has experience in this, but I am working with web services and Json.

I am trying to obtain my current geographic information (city and state) by using the Weather Underground (Weather Forecast & Reports - Long Range & Local | Wunderground | Weather Underground) API (API | Weather Underground). I want to use the geolookup feature (API | Weather Underground) to print out zipcode, city, and state.

I started it, but I am not really sure where to go from here. How should I use the geolookup function? I already created a key.

Code:
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

import com.google.gson.JsonElement;
// Requires gson jars
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class Wunderground {         
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		// Get from http://www.wunderground.com/weather/api/
		String key;
		if(args.length < 1) {
			System.out.println("Enter key: ");
			
			Scanner in = new Scanner(System.in);
			key = in.nextLine();
		} else {
			key = args[0];
		}
		
		String sURL = "http://api.wunderground.com/api/" + key + "/conditions/forecast/q/19104.json";
		
		// Connect to the URL
		URL url = new URL(sURL);
		HttpURLConnection request = (HttpURLConnection) url.openConnection();
		request.connect();
		
		// Convert to a JSON object to print data
    	JsonParser jp = new JsonParser();
    	JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
    	JsonObject rootobj = root.getAsJsonObject(); // may be Json Array if it's an array, or other type if a primitive
    	
    	// Get some data elements and print them
    	double temp_f = rootobj.get("current_observation").getAsJsonObject().get("temp_f").getAsDouble();
		System.out.println(temp_f);
		
		String todayforecast = rootobj.get("forecast").getAsJsonObject().get("txt_forecast").getAsJsonObject().get("forecastday").getAsJsonArray().get(0).getAsJsonObject().get("fcttext").getAsString();
		System.out.println(todayforecast);
	}

}

 
ssh-import-id(1)						    ssh-import							  ssh-import-id(1)

NAME
ssh-import-id - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specified file) SYNOPSIS
ssh-import-id [options] USER_ID_1 [USER_ID_2] ... [USER_ID_n] OPTIONS
-h | --help usage -o | --output F write output to file 'F' (default ~/.ssh/authorized_keys, use "-" for standard out) DESCRIPTION
This utility will securely contact a public keyserver (https://launchpad.net by default) and retrieve one or more user's public keys, and append these to the current user's ~/.ssh/authorized_keys file. The system administrator can change the source URL used by ssh-import-id(1) by editing the configuration file, /etc/ssh/ssh_import_id, which is sourced to obtain the value of URL. By default, URL="https://launchpad.net/~%s/+sshkeys". Note that this url really MUST be a secure, https url with a valid, signed certificate or else your system will be vulnerable to man-in-the-middle attacks! The "%s" will be populated by ssh-import-id(1) with the value(s) of USER_ID_1 [USER_ID_2] ... [USER_ID_n]. SEE ALSO
ssh(1) FILES
/etc/ssh/ssh_import_id AUTHOR
This manpage and the utility was written by Dustin Kirkland <kirkland@canonical.com> for Ubuntu systems (but may be used by others). Per- mission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. ssh-import 23 Feb 2010 ssh-import-id(1)
All times are GMT -4. The time now is 03:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy