Skip to content

tafallen/infohub

Repository files navigation

infohub

(A centralised group of Azure Functions that feed an infoscreen)

The APIs

GetSunTimes

Get the sunset and sunrise times for a given lattitude and longitude.

Configuration

To use this you'll need to set a environment variable containing the URI of the sunrise-sunset.org API. It's a free service. They're good people.

Local config

In your local.settings.json file add this in the values section: "sunrisesunsetapi" : "https://api.sunrise-sunset.org/json"

Server side setup

In the Application Settings area of the Azure Functions where you're deploying this you'll need to add a new setting with the name sunrisesunsetapi and the URI as shown above.

We'll be using this for all the API URLs and API Keys as it's bad practice to put them into config files. Ideally we'd secure them in KeyVault but that's for another day.

Usage

Provide the Query Params lat and lng with numerical values for for lattitude and longitude. So you'd call it like this from within Postman or from your code: https://<<your service URI>>/api/GetSunTimes?lat=<<your lattitude>>&lng=-<<your longitude>> Change the details within the <<>> to suit your service and location. And get rid of the <<>> of course. Returned is a small scrap of JSON with the sunrise and sunset times for the chosen location.

GetWeather

Gets the weather for a given location.

Configuration

This uses the Accuweather weather API from https://developer.accuweather.com/ so an account with them and an API key is required. A location key is required to get a forecast for the chosen area. Location keys can be determined using this api: https://developer.accuweather.com/accuweather-locations-api/apis.

Local config

In your local.settings.json file add this in the values section: "weatherapi" : "http://dataservice.accuweather.com/forecasts/v1/daily/5day/" "weatherapikey":"<<PUT YOUR API KEY HERE>>"

Server side setup

In the Application Settings area of the Azure Functions where you're deploying this you'll need to add a new setting with the name weatherapi and the URI as shown above. You'll also need to add weatherapikey and the api key.

Usage

Provide the Query Param location_ with the location key and you'd call it like this from within Postman or from your code: https://<<your service URI>>/api/GetWeather?location=<<Your Location Key>>

Returned is a JSON object containing a basic 5 day weather forecast, maximum and minimum temperatures and a summary forecast.

To Do

[TODO: Cache results for 12 hours]

GetNews

Gets the latest top ten news headlines from the BBC via the NewsAPI service (newsapi.org).

Configuration

Once again, this requires an API key which can be obtained from NewsAPI. The service is currently hardcoded to select the top 10 headlines from the BBC but in later updates I will add functionality to get news about specific, and from other sources.

Local config

In your local.settings.json file add this in the values section: "news_key" : "<<PUT YOUR API KEY HERE>>"

Server side setup

In the Application Settings area of the Azure Functions where you're deploying this you'll need to add a new setting with the name news_key and the api key.

Usage

Just call the service endpoint and look at the JSON returned. https://<<your service URI>>/api/GetNews

To Do

[Add details of the JSON returned] [Add the ability to customise the news feed]

GetHeating

Usage

[TODO: Add example]

To Do

The Code

C# .net Core 3.1 Azure Functions developed using VS Code.

Deployment

Currently deployed via an Azure Pipeline to an Azure Functions deployment slot.

[TODO: to write post deployment tests and, if passing, swap slots to take live.]

[TODO: Azure Function IaC code]

Why?

Well, I have an infoscren (see different github repo) and was looking to develop some more in different form factors. Rather than duplicating the Python code I wrote for that I thought that I should centralise them and then I can apply come centralised caching to reduce the load on the downstream services.

Why Azure Functions?

I've not deployed an Azure Function for years so I thought that it might be nice to see what's new, plus it's got a fairly generous free tier. Also it allowed me to tie in an Azure DevOps Pipeline for deployment and, since I was studying for a DevOps certification, I thought it would be a good learning opportunity.

Why Github?

Well, why not make the code available to everyone. I'm not looking to build a platform but if anyone can sugest improvements, or if this code can help someone else, then why not?

Where to next?

Well, I'd like to recode these in Python and Node.js as they're both interesting languages to develop for.

Releases

No releases published

Packages

No packages published

Languages