From d013701e8fcf614dadbb9aa03fd361270a9fb80d Mon Sep 17 00:00:00 2001 From: Magnus Pfeffer Date: Wed, 1 Jul 2015 12:48:25 +0200 Subject: [PATCH] initial commit --- appinfo.json | 48 +++++++++++ resources/images/pebble pendlr.png | Bin 0 -> 248 bytes src/app.js | 123 +++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 appinfo.json create mode 100644 resources/images/pebble pendlr.png create mode 100644 src/app.js diff --git a/appinfo.json b/appinfo.json new file mode 100644 index 0000000..babc968 --- /dev/null +++ b/appinfo.json @@ -0,0 +1,48 @@ +{ + "appKeys": {}, + "capabilities": [ + "location", + "configurable" + ], + "companyName": "magnuspfeffer@yahoo.de", + "longName": "Pndlr", + "projectType": "pebblejs", + "resources": { + "media": [ + { + "file": "images/menu_icon.png", + "name": "IMAGE_MENU_ICON", + "type": "png" + }, + { + "file": "images/logo_splash.png", + "name": "IMAGE_LOGO_SPLASH", + "type": "png" + }, + { + "file": "images/tile_splash.png", + "name": "IMAGE_TILE_SPLASH", + "type": "png" + }, + { + "file": "fonts/UbuntuMono-Regular.ttf", + "name": "MONO_FONT_14", + "type": "font" + }, + { + "file": "images/pebble pendlr.png", + "menuIcon": true, + "name": "IMAGES_PEBBLE_PENDLR_PNG", + "type": "png" + } + ] + }, + "sdkVersion": "3", + "shortName": "Pndlr", + "uuid": "08df6be6-16b1-4355-a85d-c463a9cd7763", + "versionCode": 1, + "versionLabel": "1.0", + "watchapp": { + "watchface": false + } +} diff --git a/resources/images/pebble pendlr.png b/resources/images/pebble pendlr.png new file mode 100644 index 0000000000000000000000000000000000000000..e46486aa0598975ffd5aac8c34069263cd993f93 GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^G9b*z3?w}c`(6i9jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCils0(?STf%O0X|CipJe;3H&EbxddW?X?_wfUrhg4Lcbjv*44RnKhX zJ>($L{Lo%BRmt$cT8EiTg^N>I%{@bpHYGZ;Kw{an^LB{Ts5iW637 literal 0 HcmV?d00001 diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..329158b --- /dev/null +++ b/src/app.js @@ -0,0 +1,123 @@ +var UI = require('ui'); +var ajax = require('ajax'); + + + +// Create a Card with title and subtitle +var card = new UI.Card({ + title:'Pndlr', + subtitle:'Fetching...', + scrollable: true +}); + +// Display the Card +card.show(); + +var cityStart = 'bla'; +var cityGoal = 'bla'; + + +// Where are we? +var geolocation = (function() { + //'use strict'; + + //var geoposition; + var options = { + maximumAge: 1000, + timeout: 15000, + enableHighAccuracy: false + }; + + function _onSuccess (callback, position) { + console.log('DEVICE POSITION'); + console.log('LAT: ' + position.coords.latitude + ' - LON: ' + position.coords.longitude); + + var lat = position.coords.latitude; + //var long = pos.coords.longitude; + + if (Math.abs(lat - 48.7) < Math.abs(lat - 49.4)) { + cityStart = 'Stuttgart'; + cityGoal = 'Mannheim'; + } + else { + cityStart = 'Mannheim'; + cityGoal = 'Stuttgart'; + } + callback(); + } + + function _onError (callback, error) { + console.log(error); + cityStart = 'Stuttgart'; + cityGoal = 'Mannheim'; + callback(); + } + + function _getLocation (callback) { + navigator.geolocation.getCurrentPosition( + _onSuccess.bind(this, callback), + _onError.bind(this, callback), + options + ); + } + + return { + location: _getLocation + }; + +}()); + +geolocation.location(function () { + console.log('finished, loading app.'); + var URL = 'http://mobile.bahn.de/bin/mobil/query.exe/dn?S='+ cityStart + '&Z=' +cityGoal + '&start=1'; +console.log(URL); +//var URL = 'http://mobile.bahn.de/bin/mobil/query.exe/dox?S=mannheim&Z=stuttgart&start=1'; + + +// Make the request +ajax( + { + url: URL}, + function(data) { + // Success! + console.log("Successfully fetched DB data!"); + + // Extract data + + var result = ""; + var re = /class=.timetx..\sab\s..td.\s.td class=.time..\s(.*)\s.nbsp.(.*)\s..td.\s.td class=.duration lastrow. rowspan=.2..\s(.*)\s..td./g; + var myArray; + + while ((myArray = re.exec(data)) !== null){ + + var start = myArray[1]; + var info = myArray[2]; + var duration = myArray[3]; + + if (/\+\d*..span/i.test(info)) { + var re2 = /(\+\d*)..span/i; + var arr2 = re2.exec(info); + info = arr2[1]; + } + else { + info = "W!"; + } + result += start + " (" + duration +") " + " " + info + "\n"; + //result += "--------\n"; + } + + // Show to user + card.subtitle(cityStart.substring(0,3) + "->" + cityGoal.substring(0,3)); //+ " lat:" + lat + " long:" +long); + card.body(result); + }, + function(error) { + // Failure! + console.log('Failed fetching DB data: ' + error); + card.subtitle(cityStart + "->" + cityGoal); + card.body("Error!"); + } +); +}); + + +