Permalink
Browse files

added reverse geo

  • Loading branch information...
davidhampgonsalves committed Jan 11, 2012
1 parent 02572cd commit 9ec04efc297161b19ed8aed07222e467957a461a
View
@@ -3,7 +3,9 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/home/david/workspace/lib/xpp3-1.1.4c.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry exported="true" kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER/App Engine"/>
<classpathentry kind="lib" path="/home/david/workspace/lib/joda-time-1.6.2.jar"/>
+ <classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
+ <classpathentry kind="lib" path="/home/david/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/com.google.appengine.eclipse.sdkbundle_1.6.1.v201112160242r37/appengine-java-sdk-1.6.1/lib/appengine-remote-api.jar"/>
+ <classpathentry kind="lib" path="/home/david/workspace/lib/json-org.jar"/>
<classpathentry kind="output" path="war/WEB-INF/classes"/>
</classpath>
@@ -1,4 +1,7 @@
-#Fri Nov 25 15:41:47 AST 2011
+#Sat Dec 17 08:15:28 AST 2011
eclipse.preferences.version=1
-filesCopiedToWebInfLib=appengine-jsr107cache-1.5.0.1.jar|appengine-api-labs-1.5.0.1.jar|datanucleus-core-1.1.5.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|datanucleus-appengine-1.0.8.final.jar|appengine-api-1.0-sdk-1.5.0.1.jar|jsr107cache-1.1.jar
+filesCopiedToWebInfLib=appengine-jsr107cache-1.6.1.jar|datanucleus-core-1.1.5.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar|datanucleus-appengine-1.0.10.final.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|appengine-api-labs-1.6.1.jar|appengine-api-1.0-sdk-1.6.1.jar|jsr107cache-1.1.jar|google_sql.jar
gaeDeployDialogSettings=
+gaeIsEclipseDefaultInstPath=true
+googleCloudSqlEnabled=false
+localDevMySqlEnabled=true
@@ -1,59 +0,0 @@
-package com.hourlyweather.web;
-
-import java.util.HashMap;
-import java.util.Set;
-
-import org.joda.time.DateTimeZone;
-
-/**
- * Provides Locations for city names. Currently this is just building a static
- * hashmap of names but later this should be moved to the datastore if more
- * cities get added.
- *
- * @author dave
- *
- */
-public class CityLocationUtil {
-
- private static final HashMap<String, Location> cityLocations = new HashMap<String, Location>();
-
- static {
- cityLocations.put("toronto", new Location(43.65, -79.38, "America/Toronto"));
- cityLocations.put("quebec", new Location(46.83, -71.25, "Canada/Eastern"));
- cityLocations.put("vancouver", new Location(49.26, -123.11, "America/Vancouver"));
- cityLocations.put("halifax", new Location(44.50, -63.46, "America/Halifax"));
-
- cityLocations.put("new york", new Location(40.77, -73.98, "America/New_York"));
- cityLocations.put("los angeles", new Location(33.93, -118.4, "America/Los_Angeles"));
- cityLocations.put("chicago", new Location(41.90, 87.65, "America/Chicago"));
- cityLocations.put("san francisco", new Location(37.75, -122.68, "US/Pacific"));
- cityLocations.put("seattle", new Location(47.45, -122.30, "US/Pacific"));
-
- cityLocations.put("london", new Location(51.5, -0.12, "Europe/London"));
- cityLocations.put("melbourne", new Location(0, 0, "Australia/Melbourne"));
- cityLocations.put("tokyo", new Location(0, 0, "Asia/Tokyo"));
- cityLocations.put("moscow", new Location(0, 0, "Europe/Moscow"));
- }
-
- /**
- * Returns a Location for a city name
- *
- * @param city
- * @return
- */
- public static Location getLocation(String city) {
- return cityLocations.get(city.toLowerCase());
- }
-
- public static Set<String> getLocations() {
- return cityLocations.keySet();
- }
-
- public static DateTimeZone getTimezone(String city) {
- city = city.toLowerCase();
- Location location;
- if((location = cityLocations.get(city.toLowerCase())) != null)
- return location.getTimeZone();
- return null;
- }
-}
@@ -9,17 +9,17 @@
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
-import com.google.appengine.repackaged.org.json.JSONArray;
-import com.google.appengine.repackaged.org.json.JSONException;
-import com.google.appengine.repackaged.org.json.JSONObject;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import com.hourlyweather.forecast.ForecastHour;
import com.hourlyweather.forecast.HourlyForecast;
public class HourlyForecastBuilder {
private static final DateTimeFormatter dayFormatter = DateTimeFormat
.forPattern("EEEE, MMMM dd");
private static final DateTimeFormatter hourFormatter = DateTimeFormat
- .forPattern("hh:00 aa");
+ .forPattern("HH");
private static final DecimalFormat windSpeedFormat = new DecimalFormat(
"#.#");
@@ -8,26 +8,34 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.google.appengine.api.datastore.DatastoreService;
+import com.google.appengine.api.datastore.DatastoreServiceFactory;
+import com.google.appengine.api.datastore.EntityNotFoundException;
+import com.google.appengine.api.datastore.Key;
+import com.google.appengine.api.datastore.KeyFactory;
+
@SuppressWarnings("serial")
public class HourlyWeatherByCityForward extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
- String city = request.getRequestURI();
- city = city.substring(city.lastIndexOf('/') + 1);
- city = city.trim();
- city = city.replaceAll("%20", " ");
- request.setAttribute("city", city);
-
- Location location = CityLocationUtil.getLocation(city);
-
- if (location == null)
- throw new LocationException(city + " wasn't found.");
+ Key cityKey = KeyFactory.createKey(City.ENTITY, request.getParameter("id"));
+
+ //query database for city geo data
+ DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
- request.setAttribute("lat", location.getLat());
- request.setAttribute("lon", location.getLon());
- request.setAttribute("timeOffset", location.getTimeZone());
+ City city;
+ try {
+ city = new City(ds.get(cityKey));
+ } catch (EntityNotFoundException e) {
+ throw new LocationException(cityKey + " wasn't found.");
+ }
+
+ request.setAttribute("city", city.getName());
+ request.setAttribute("lat", city.getLatitude());
+ request.setAttribute("lon", city.getLongitude());
+ request.setAttribute("timeOffset", city.getTimezone());
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher("/");
@@ -1,36 +0,0 @@
-package com.hourlyweather.web;
-
-import org.joda.time.DateTimeZone;
-
-public class Location
-{
- private Double lat, lon;
- private DateTimeZone timeZone;
-
- public Location(double lat, double lon, String timeZoneId) {
- this.lat = lat;
- this.lon = lon;
- timeZone = DateTimeZone.forID(timeZoneId);
- }
-
- public Double getLat()
- {
- return lat;
- }
-
- public void setLon(Double lon)
- {
- this.lon = lon;
- }
-
- public Double getLon()
- {
- return lon;
- }
-
- public DateTimeZone getTimeZone() {
- return timeZone;
- }
-
-
-}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -13,6 +13,17 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
<servlet-name>HourlyWeatherByCity</servlet-name>
<servlet-class>com.hourlyweather.web.HourlyWeatherByCityForward</servlet-class>
</servlet>
+
+ <servlet>
+ <display-name>Remote API Servlet</display-name>
+ <servlet-name>RemoteApiServlet</servlet-name>
+ <servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>RemoteApiServlet</servlet-name>
+ <url-pattern>/remote_api</url-pattern>
+ </servlet-mapping>
<servlet-mapping>
<servlet-name>HourlyWeatherByCity</servlet-name>
Oops, something went wrong.

0 comments on commit 9ec04ef

Please sign in to comment.