Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/webcamps-api-v3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Oct 22, 2023
2 parents 3388e8c + d08f601 commit ab7315f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
5 changes: 2 additions & 3 deletions lib/client/resort/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function render(div, webcams) {
});
}

// div.webcam.mobile
// div.webcam
// a
// img.active
// img.inactive
Expand Down Expand Up @@ -100,8 +100,7 @@ function render(div, webcams) {
} else {
cam = ul.appendChild(li[0].cloneNode(true));
}
initCam(cam.querySelector('.desktop'), webcam);
initCam(cam.querySelector('.mobile'), webcam.mobile || webcam);
initCam(cam.querySelector('.webcam'), webcam);
});
for (let i = Math.max(1, webcams.length); i < li.length; i++) {
ul.removeChild(li[i]);
Expand Down
38 changes: 16 additions & 22 deletions lib/webcams.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const superagent = require('superagent');
const debug = require('debug')('liftie:webcams');

const { day } = require('./tools/millis');
const { minute } = require('./tools/millis');
const limiter = require('./tools/limiter');

const userAgent = 'Mozilla/5.0 (compatible; Liftie/1.0; +https://liftie.info)';

module.exports = fetch;
module.exports.interval = {
active: day,
active: 8.5 * minute, // v3 API images are only valid for 10 minutes
inactive: Infinity
};

Expand All @@ -19,19 +19,13 @@ const notice = `Webcams provided by
`;


function convert({ title, image, url }) {
function convert({ title, images, urls }) {
const name = title.replace(/'/g, '&apos;');
return {
name,
source: url.current.desktop,
image: image.current.preview,
notice,
mobile: {
name,
source: url.current.mobile,
image: image.current.preview,
notice
}
source: urls.detail,
image: images.current.preview,
notice
};
}

Expand All @@ -57,11 +51,15 @@ function fetch(resort, fn) {
debug("fetch webcams from Windy for %s", resort.id);

const { ll: [lon, lat] } = resort;
const url = `https://api.windy.com/api/webcams/v2/list/nearby=${lat},${lon},5/limit=5?show=webcams:image,url`;
const url = new URL('https://api.windy.com/webcams/api/v3/webcams');
const { searchParams: sp } = url;
sp.set('limit', 5);
sp.set('nearby', `${lat},${lon},5`);
sp.set('include', 'images,urls');
superagent(url)
.set('User-Agent', userAgent)
.accept('application/json')
.set("x-windy-key", WEBCAMS_API_KEY)
.set("x-windy-api-key", WEBCAMS_API_KEY)
.then(onData, onError);

function onError(err) {
Expand All @@ -70,16 +68,12 @@ function fetch(resort, fn) {
}

function onData({ body }) {
const { status, result } = body;
if (status !== 'OK') {
debug('Invalid response', status);
return fn(null, getStatic(resort));
}
if (result.webcams.length < 1) {
const { webcams } = body;
if (webcams.length < 1) {
return fn(null, getStatic(resort));
}
debug('Webcam API response', result.webcams);
fn(null, result.webcams.map(convert));
debug('Webcam API response', webcams);
fn(null, webcams.map(convert));
}
});
}
8 changes: 2 additions & 6 deletions public/stylesheets/style.styl
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ header .ls-furkot

.webcam
max-width 100%
display inline-block

>a
display block
Expand All @@ -366,11 +367,6 @@ header .ls-furkot
margin-bottom .5em
text-align center

&.desktop
display inline-block
&.mobile
display none

.snow
.value
display inline-block
Expand Down Expand Up @@ -505,7 +501,7 @@ for col in 4 3 2 1
display none

@media screen and (max-width: 400px)
.extras .webcams .webcam
.extras
&.desktop
display none

Expand Down
16 changes: 9 additions & 7 deletions test/replay/api.windy.com-443/webcam
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
GET /api/webcams/v2/list/nearby=46.54,7.98,5/limit=5?show=webcams:image,url
GET /webcams/api/v3/webcams?limit=5&nearby=46.54%2C7.98%2C5&include=images%2Curls
accept-encoding: gzip, deflate
accept: application/json

HTTP/1.1 200 OK
x-powered-by: Express
vary: Origin, accept-encoding
access-control-allow-origin: *
x-powered-by: node-webcams2-public-76489fc869-dzj29: v2.6.8 webcams2
cache-control: private, no-cache, no-store, must-revalidate
expires: -1
pragma: no-cache
content-type: application/json; charset=utf-8
vary: Accept-Encoding
date: Tue, 19 May 2020 13:04:50 GMT
date: Sun, 22 Oct 2023 11:29:33 GMT
via: 1.1 google
alt-svc: clear
connection: close
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
transfer-encoding: chunked

{"status":"OK","result":{"offset":0,"limit":5,"total":1,"webcams":[{"id":"1329413077","status":"active","title":"Fieschertal: Jungfrau - Wengen - Interlaken","image":{"current":{"icon":"https://images-webcams.windy.com/77/1329413077/current/icon/1329413077.jpg","thumbnail":"https://images-webcams.windy.com/77/1329413077/current/thumbnail/1329413077.jpg","preview":"https://images-webcams.windy.com/77/1329413077/current/preview/1329413077.jpg","toenail":"https://images-webcams.windy.com/77/1329413077/current/thumbnail/1329413077.jpg"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224},"toenail":{"width":200,"height":112}},"daylight":{"icon":"https://images-webcams.windy.com/77/1329413077/daylight/icon/1329413077.jpg","thumbnail":"https://images-webcams.windy.com/77/1329413077/daylight/thumbnail/1329413077.jpg","preview":"https://images-webcams.windy.com/77/1329413077/daylight/preview/1329413077.jpg","toenail":"https://images-webcams.windy.com/77/1329413077/daylight/thumbnail/1329413077.jpg"},"update":1589889677},"url":{"current":{"desktop":"https://www.windy.com/webcams/1329413077","mobile":"https://www.windy.com/webcams/1329413077"},"edit":"https://www.windy.com/webcams/1329413077","daylight":{"desktop":"https://www.windy.com/webcams/1329413077","mobile":"https://www.windy.com/webcams/1329413077"}}}]}}
{"total":6,"webcams":[{"title":"Fieschertal: Jungfraujoch","viewCount":94,"webcamId":1697038975,"status":"active","lastUpdatedOn":"2023-10-20T15:40:53.000Z","images":{"current":{"icon":"https://images-webcams.windy.com/public/75/1697038975/current/icon/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2N1cnJlbnQvaWNvbi8xNjk3MDM4OTc1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.ZzIQuUMV0qUdJuQvxzF-59FMjOvWIBPSWpn9NBLUx90","thumbnail":"https://images-webcams.windy.com/public/75/1697038975/current/thumbnail/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2N1cnJlbnQvdGh1bWJuYWlsLzE2OTcwMzg5NzUuanBnIiwiaWF0IjoxNjk3OTc0MTczLCJleHAiOjE2OTc5NzQ3NzN9.qny-AhpNJOP-U1ycXQGWSJxMzGZZjH6MvTsUvZm5MTc","preview":"https://images-webcams.windy.com/public/75/1697038975/current/preview/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2N1cnJlbnQvcHJldmlldy8xNjk3MDM4OTc1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.QyFD8DWPywSbzPgK1vFSw25qufS0mMW8POZzrW5l-qc"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224}},"daylight":{"icon":"https://images-webcams.windy.com/public/75/1697038975/daylight/icon/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2RheWxpZ2h0L2ljb24vMTY5NzAzODk3NS5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.XdLStlf_Ev7NiX61CA6wwqrWfTmU0gjB4frqy626CPs","thumbnail":"https://images-webcams.windy.com/public/75/1697038975/daylight/thumbnail/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2RheWxpZ2h0L3RodW1ibmFpbC8xNjk3MDM4OTc1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.iX5HiSTA47e8ff2b3IciJwb1Hn_TkpDvxYDg_EEtGSY","preview":"https://images-webcams.windy.com/public/75/1697038975/daylight/preview/1697038975.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83NS8xNjk3MDM4OTc1L2RheWxpZ2h0L3ByZXZpZXcvMTY5NzAzODk3NS5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.SEBlBBrbP_mAPu7CMDsgef2KczTF_UeunIQYgaxp5fg"}},"urls":{"detail":"https://windy.com/webcams/1697038975","edit":"https://windy.com/webcams/edit/1697038975","provider":"https://www.jungfrau.ch/de-ch/"}},{"title":"Lauterbrunnen: Ostgrat","viewCount":99,"webcamId":1697032276,"status":"active","lastUpdatedOn":"2023-10-22T10:23:24.000Z","images":{"current":{"icon":"https://images-webcams.windy.com/public/76/1697032276/current/icon/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2N1cnJlbnQvaWNvbi8xNjk3MDMyMjc2LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.HP2ZkruGaC147XSgBgqjSxlm_Hs0eiF_C3t2tVg5Qhk","thumbnail":"https://images-webcams.windy.com/public/76/1697032276/current/thumbnail/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2N1cnJlbnQvdGh1bWJuYWlsLzE2OTcwMzIyNzYuanBnIiwiaWF0IjoxNjk3OTc0MTczLCJleHAiOjE2OTc5NzQ3NzN9.4kr2eE0037wH1Upx86nyIbAZcswHBGix3STDBtb0ly4","preview":"https://images-webcams.windy.com/public/76/1697032276/current/preview/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2N1cnJlbnQvcHJldmlldy8xNjk3MDMyMjc2LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.by8VoUEb3XrQIO1IOIsceMl93M6HqYLI5wXanJlPVuY"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224}},"daylight":{"icon":"https://images-webcams.windy.com/public/76/1697032276/daylight/icon/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2RheWxpZ2h0L2ljb24vMTY5NzAzMjI3Ni5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.TpWZnnpBZZwG0FSnBh8d3N3e6F7n8LmN7cuKwA2SFiE","thumbnail":"https://images-webcams.windy.com/public/76/1697032276/daylight/thumbnail/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2RheWxpZ2h0L3RodW1ibmFpbC8xNjk3MDMyMjc2LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.MVKUjNSkA2s0Zi8YN956hz_EXavuU1XurIrY_aZAjMY","preview":"https://images-webcams.windy.com/public/76/1697032276/daylight/preview/1697032276.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ni8xNjk3MDMyMjc2L2RheWxpZ2h0L3ByZXZpZXcvMTY5NzAzMjI3Ni5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.trfU8Pl_N2vxUybwRkh3QEmkiWgMGOKrZLYI5na3aRU"}},"urls":{"detail":"https://windy.com/webcams/1697032276","edit":"https://windy.com/webcams/edit/1697032276","provider":"https://www.jungfrau.ch/de-ch/?utm_campaign=Webcams+Jungfraubahnen&utm_term=jungfrau-home&utm_content=DE&utm_source=website-jbm-webcams&utm_medium=logo-links-oben"}},{"title":"Fieschertal: Jungfrau - Wengen - Interlaken","viewCount":108509,"webcamId":1329413077,"status":"active","lastUpdatedOn":"2023-10-22T10:29:05.000Z","images":{"current":{"icon":"https://images-webcams.windy.com/public/77/1329413077/current/icon/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2N1cnJlbnQvaWNvbi8xMzI5NDEzMDc3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.YP4Ft_kzlYijFO-vDonVOnhn4F_0DoI3gkupyorqF9A","thumbnail":"https://images-webcams.windy.com/public/77/1329413077/current/thumbnail/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2N1cnJlbnQvdGh1bWJuYWlsLzEzMjk0MTMwNzcuanBnIiwiaWF0IjoxNjk3OTc0MTczLCJleHAiOjE2OTc5NzQ3NzN9.D3_WXwu5P2OsKVhjGiyGuD8b-AK4hOg2K-KnboiF8TA","preview":"https://images-webcams.windy.com/public/77/1329413077/current/preview/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2N1cnJlbnQvcHJldmlldy8xMzI5NDEzMDc3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.TOhYN_-Q9g4KU_xlfSZgJ8ZfYCDOVTWE43FuHxSk6o8"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224}},"daylight":{"icon":"https://images-webcams.windy.com/public/77/1329413077/daylight/icon/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2RheWxpZ2h0L2ljb24vMTMyOTQxMzA3Ny5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.07BWhFhNBwnPLdvx3gTqQD-D33oLZN49IY-qHOEwVrg","thumbnail":"https://images-webcams.windy.com/public/77/1329413077/daylight/thumbnail/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2RheWxpZ2h0L3RodW1ibmFpbC8xMzI5NDEzMDc3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.jnBy464FGbavV9Rdr5glEuDXNMVI-0yuzIxgcBAyAN4","preview":"https://images-webcams.windy.com/public/77/1329413077/daylight/preview/1329413077.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy83Ny8xMzI5NDEzMDc3L2RheWxpZ2h0L3ByZXZpZXcvMTMyOTQxMzA3Ny5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.rCC5zcVus8ZOsAqcdmQ6NymClErN-IckJjXm2u2yCOE"}},"urls":{"detail":"https://windy.com/webcams/1329413077","edit":"https://windy.com/webcams/edit/1329413077","provider":"https://www.switch.ch/cam/"}},{"title":"Fieschertal: Mönchsjochhütte","viewCount":146,"webcamId":1697041107,"status":"active","lastUpdatedOn":"2023-10-22T11:13:38.000Z","images":{"current":{"icon":"https://images-webcams.windy.com/public/07/1697041107/current/icon/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2N1cnJlbnQvaWNvbi8xNjk3MDQxMTA3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.Vh9wHkm9nn9mQvwEjEDCdF9C9S6zNFDOYdtVdDbJgz4","thumbnail":"https://images-webcams.windy.com/public/07/1697041107/current/thumbnail/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2N1cnJlbnQvdGh1bWJuYWlsLzE2OTcwNDExMDcuanBnIiwiaWF0IjoxNjk3OTc0MTczLCJleHAiOjE2OTc5NzQ3NzN9.yleb3LJm-TrUfMH5T_nY0NKCOpMJTbK2Z--junbiy3k","preview":"https://images-webcams.windy.com/public/07/1697041107/current/preview/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2N1cnJlbnQvcHJldmlldy8xNjk3MDQxMTA3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.3yW0Mvv7wH0mSMzG2a1wBeOpfBshLlTlxwJhsyr4dXE"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224}},"daylight":{"icon":"https://images-webcams.windy.com/public/07/1697041107/daylight/icon/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2RheWxpZ2h0L2ljb24vMTY5NzA0MTEwNy5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.PWDIMIvaEeV3TJZIQ2nyOGamMI37jL_QVV8Oi_QHclY","thumbnail":"https://images-webcams.windy.com/public/07/1697041107/daylight/thumbnail/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2RheWxpZ2h0L3RodW1ibmFpbC8xNjk3MDQxMTA3LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.ePYnGy3N4WdPfpi-RYn3MWCBqeFKKZnwxjzm5JqfZBg","preview":"https://images-webcams.windy.com/public/07/1697041107/daylight/preview/1697041107.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8wNy8xNjk3MDQxMTA3L2RheWxpZ2h0L3ByZXZpZXcvMTY5NzA0MTEwNy5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.-Gfz1xgMcquGc5PlMR06mHOoBnaXhyXUOQxAGBDLm1o"}},"urls":{"detail":"https://windy.com/webcams/1697041107","edit":"https://windy.com/webcams/edit/1697041107","provider":"https://moenchsjochhuette.roundshot.com/"}},{"title":"Fieschertal › South-West: Jungfraujoch -> SW","viewCount":3902,"webcamId":1649592335,"status":"active","lastUpdatedOn":"2023-10-22T10:39:33.000Z","images":{"current":{"icon":"https://images-webcams.windy.com/public/35/1649592335/current/icon/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2N1cnJlbnQvaWNvbi8xNjQ5NTkyMzM1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.piFuAJtxYdb3u_nok6dzIU0GacK0mHhUPKWU06FTwiw","thumbnail":"https://images-webcams.windy.com/public/35/1649592335/current/thumbnail/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2N1cnJlbnQvdGh1bWJuYWlsLzE2NDk1OTIzMzUuanBnIiwiaWF0IjoxNjk3OTc0MTczLCJleHAiOjE2OTc5NzQ3NzN9.Bc0od0GZs4B1a9gVk3eM5Vi9Sq5UAyKO3c84k_cpIZo","preview":"https://images-webcams.windy.com/public/35/1649592335/current/preview/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2N1cnJlbnQvcHJldmlldy8xNjQ5NTkyMzM1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.BMXjJxptv_BkK8FbHJS9knALIlGpmyeopZF2Y3sfRFw"},"sizes":{"icon":{"width":48,"height":48},"thumbnail":{"width":200,"height":112},"preview":{"width":400,"height":224}},"daylight":{"icon":"https://images-webcams.windy.com/public/35/1649592335/daylight/icon/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2RheWxpZ2h0L2ljb24vMTY0OTU5MjMzNS5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.p58MwVsrzkccl9NVb0zm8mWqLkWwy208l82eK_B4sGk","thumbnail":"https://images-webcams.windy.com/public/35/1649592335/daylight/thumbnail/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2RheWxpZ2h0L3RodW1ibmFpbC8xNjQ5NTkyMzM1LmpwZyIsImlhdCI6MTY5Nzk3NDE3MywiZXhwIjoxNjk3OTc0NzczfQ.YXbH9e-Jmh4BUf_-vIIGgU-Jl71MAGgBLQrMg3h7KRU","preview":"https://images-webcams.windy.com/public/35/1649592335/daylight/preview/1649592335.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbWFnZV9wYXRoIjoiL3B1YmxpYy8zNS8xNjQ5NTkyMzM1L2RheWxpZ2h0L3ByZXZpZXcvMTY0OTU5MjMzNS5qcGciLCJpYXQiOjE2OTc5NzQxNzMsImV4cCI6MTY5Nzk3NDc3M30.QRAno30XWX6mHUwvNgiVUoUcUgBXFwn4UT880Zp3Ol0"}},"urls":{"detail":"https://windy.com/webcams/1649592335","edit":"https://windy.com/webcams/edit/1649592335","provider":"https://allsky7.net/index.html?&station=AMS201#realtimetab"}}]}
25 changes: 9 additions & 16 deletions test/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const webcams = require('../lib/webcams');

require('./replay');

if (process.env.REPLAY !== 'record') {
process.env.WEBCAMS_API_KEY = 'TEST_KEY';
}

test('webcams should return no webcams if location is missing', function (t, done) {
webcams({}, function (err, webcams) {
assert.ifError(err);
Expand All @@ -12,12 +16,10 @@ test('webcams should return no webcams if location is missing', function (t, don
});
});


test('webcams should return webcams for valid location', function (t, done) {
process.env.WEBCAMS_API_KEY = 'TEST_KEY';
webcams({
counter: 1,
ll: [7.98, 46.54] // from API examples https://developers.webcams.travel/#webcams/examples
ll: [7.98, 46.54] // from API examples https://windy.com/webcams/1697038975'
}, function (err, webcams) {
delete process.env.WEBCAMS_API_KEY;

Expand All @@ -27,19 +29,10 @@ test('webcams should return webcams for valid location', function (t, done) {

const webcam = webcams[0];

assert.equal(webcam.name, 'Fieschertal: Jungfrau - Wengen - Interlaken');
assert.ok(webcam.source.startsWith('https://www.windy.com/webcams/1329413077'));
assert.ok(webcam.image.startsWith('https://images-webcams.windy.com'));
assert.ok(webcam.notice.startsWith('Webcams provided by\n<a href="https://www.windy.com/"'));

assert.equal(typeof webcam.mobile, 'object');

const mobile = webcam.mobile;

assert.equal(mobile.name, 'Fieschertal: Jungfrau - Wengen - Interlaken');
assert.ok(mobile.source.startsWith('https://www.windy.com/webcams/1329413077'));
assert.ok(mobile.image.startsWith('https://images-webcams.windy.com'));
assert.ok(mobile.notice.startsWith('Webcams provided by\n<a href="https://www.windy.com/"'));
assert.equal(webcam.name, 'Fieschertal: Jungfraujoch');
assert.equal(webcam.source, 'https://windy.com/webcams/1697038975');
assert.match(webcam.image, /^https:\/\/images-webcams.windy.com\//);
assert.match(webcam.notice, /^Webcams provided by\n<a href="https:\/\/www.windy.com\/"/);

done();
});
Expand Down
Loading

0 comments on commit ab7315f

Please sign in to comment.