Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

rWeather - Weather API

Featured Replies

Currently working on a weather application for fun and experience. Feel free to use as well as give me some feedback smile.png

package com.reiddacosta.rweather;

import java.io.IOException;

import com.reiddacosta.rweather.api.Weather;

/**
 * rWeather v1.0
 * 
 * @author Reid DaCosta
 *
 */
public class rWeather {

	public static void main(String[] args) throws IOException {
		System.out.println(new Weather().getTemperature());
	}
}

package com.reiddacosta.rweather.api;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * Weather Class
 * 
 * @author Reid DaCosta
 *
 */
public class Weather {

	private static final String BASE = "https://api.forecast.io/forecast/477268b98a0bc386f1e6e624777a6077/";
	private String userLatitude;
	private String userLongitude;
	private int userTemperature;
	private Location location;

	/**
	 * Default Constructor
	 * 
	 * @throws IOException
	 */
	public Weather() throws IOException {
		location = new Location();
		this.userLatitude = location.getLatitude();
		this.userLongitude = location.getLongitude();
		userTemperature = (int) toCelsius(getUserTeperature());
	}
	
	/**
	 * Returns the temperature for the user based on their location.
	 * 
	 * @return userTemperature
	 */
	public int getTemperature() {
		return userTemperature;
	}
	
	/**
	 * Sets the temperature for the user.
	 * 
	 * @param userTemperature
	 */
	public void setTemperature(int userTemperature){
		this.userTemperature = userTemperature;
	}

	/**
	 * Returns the temperature based on the users location.
	 * 
	 * @return userTeperature
	 * @throws IOException
	 */
	private String getUserTeperature() throws IOException {
		final URL url = new URL(BASE + userLatitude + "," + userLongitude);
		BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
		String line, almost;
		String userTeperature = null;
		while ((line = file.readLine()) != null) {
			if (line.contains("apparentTemperature")) {
				userTeperature = (line);
			}
		}
		file.close();
		almost = userTeperature.substring(userTeperature.indexOf("apparentTemperature"),userTeperature.indexOf("dewPoint"));
		return almost.substring(almost.indexOf(":") + 1, almost.indexOf(","));
	}

	/**
	 * Returns the temperature in Celsius.
	 * 
	 * @param fahTemp
	 * @return tempCelsius
	 */
	private double toCelsius(String fahTemp) {
		return (int) (Double.parseDouble(fahTemp) - 32) * 5 / 9;
	}
}

package com.reiddacosta.rweather.api;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * Location Class
 * 
 * @author Reid DaCosta
 *
 */
public class Location {

	private static final String BASE = "http://whatsmylatlng.com";
	private String userLocation;
	private String userLatitude;
	private String userLongitude;

	/**
	 * Default Constructor
	 * 
	 * @throws IOException
	 */
	public Location() throws IOException {
		this.userLocation = getuserLocation();
		this.userLatitude = userLocation.substring(0, userLocation.indexOf(","));
		this.userLongitude = userLocation.substring(userLocation.indexOf(",") + 1, userLocation.length());
	}

	/**
	 * Returns the Latitude of the user.
	 * 
	 * @return userLatitude
	 */
	public String getLatitude() {
		return userLatitude.trim();
	}
	
	/**
	 * Sets the Latitude of the user.
	 * 
	 * @param userLatitude
	 */
	public void setLatitude(String userLatitude) {
		this.userLatitude = userLatitude;
	}

	/**
	 * Returns the Longitude of the user.
	 * 
	 * @return userLongitude
	 */
	public String getLongitude() {
		return userLongitude.trim();
	}
	
	/**
	 * Sets the Longitude of the user.
	 * 
	 * @param userLongitude
	 */
	public void setLongitude(String userLongitude){
		this.userLongitude = userLongitude;
	}

	/**
	 * Returns the Latitude & Longitude of the user.
	 * 
	 * @return userLocation
	 * @throws IOException
	 */
	private String getuserLocation() throws IOException {
		final URL url = new URL(BASE);
		BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
		String line;
		String userLocation = null;
		while ((line = file.readLine()) != null) {
			if (line.contains("geo.initialize")) {
				userLocation = (line);
			}
		}
		file.close();
		return userLocation.substring(userLocation.indexOf("(") + 1,userLocation.indexOf(")"));
	}
}

Edited by Reid

  • 2 weeks later...

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.