-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getCachedData, putCachedData } from "./cache.mjs"; | ||
|
||
export const wxDiscussion = async () => { | ||
let wxdisc = getCachedData('wxdisc'); | ||
if (!wxdisc) { | ||
const response = await fetch('https://a.atmos.washington.edu/data/disc_report.html'); | ||
const text = await response.text(); | ||
const start = 'Area Forecast Discussion\nNational Weather Service Seattle WA'; | ||
const startIndex = text.indexOf(start); | ||
const end = '$$'; | ||
const endIndex = text.indexOf(end, startIndex); | ||
wxdisc = { | ||
text: text.substring(startIndex, endIndex) | ||
}; | ||
putCachedData('wxdisc', wxdisc); | ||
} | ||
let text = wxdisc.text.replace(/(?<!\n)\n(?!\n)/g, ' '); // Remove all newlines, except for those that start a new paragraph (two consecutive newlines) | ||
return text; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { printToday } from '../src/index.mjs'; | ||
import { wxDiscussion } from '../src/wx.mjs'; | ||
|
||
export default async function (context, req) { | ||
context.log('Starting execution'); | ||
try { | ||
const utcOffset = req.query && req.query.utcOffset; | ||
context.res = { | ||
status: 200, | ||
body: await printToday(utcOffset) | ||
}; | ||
const source = req.query?.source ?? ''; | ||
if (source === 'wxdisc') { | ||
context.res = { | ||
status: 200, | ||
body: await wxDiscussion() | ||
}; | ||
} else { | ||
const utcOffset = req.query && req.query.utcOffset; | ||
context.res = { | ||
status: 200, | ||
body: await printToday(utcOffset) | ||
}; | ||
} | ||
} catch (err) { | ||
context.res = { | ||
status: 500, | ||
body: 'Error' | ||
}; | ||
context.log(`Error: ${err}`); | ||
context.log(`Error: ${err}\n${err.stack}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.