#
👮 Find-CrimeUK Powershell Module
I believe members of the public have the right to know about crime in the area they live-in within the United Kingdom. Even the crime that is not reported in the papers. The UK police have a public API which can give you this information, however it is not easy enough for the general public to use or even know it exists. I want to bridge those gaps
#
Powershell Function 🚓
Yep same boring old story, I been looking at existing public APIs out there that require no authentication or key to be used. This is so if you do decide to download this module you do not need to sign up for an API key.
I had a mate phone me about all these cops that were parked up down the road, seemed like a pretty big raid to have that much police and wagons involved. Anyways that got me thinking I wonder if this will be in the local paper? Will I ever know about what type of crime was happening around the corner? I feel like I had a right to know, but in reality it probably will not appear in the paper.
So a bit of internet searching later, and I found that the UK police force has an API which will allow me to obtain this information. Although this information might not be updated immediately I am confident that it will be on there once the police record it.
However if you look at the API instead of the Police making this easy enough for the general public to use, they made it so it would only accept the URL if it contained a latitude and longitude and the date in a YYYY-MM format. A bit like the internet us humans cannot remember long number of digits like random IP addresses or longitudes or latitudes. So I built in a sub-function to allow me to over-come this. For this I used the following API
Using this API as a sub-function it would allow me to use location names in the main-function, rather than getting the end-user to look up their latitude and longitude location to be able to use this function. So in my head this is what the police should have done to make this more user-friendly. I can only assume they did not, as when you specify a city name, this can return lots of different latitudes and longitudes for that destination.
#
Did you miss the last few blogs? ⚠️
Just in-case you missed the last blog, or you are just reading particular blogs, or this could possile be your first blog let us just quickly go over an API again...Please skip if this if you already read it in the last blog...or previous blog to that, or maybe the one before that.
#
API ℹ️
You may or may not know about API aka Application Programming Interface. So here is some brief documentation
API An application programming interface is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build or use such a connection or interface is called an API specification. A computer system that meets this standard is said to implement or expose an API. The term API may refer either to the specification or to the implementation. In contrast to a user interface, which connects a computer to a person, an application programming interface connects computers or pieces of software to each other. It is not intended to be used directly by a person other than a computer programmer who is incorporating it into the software. An API is often made up of different parts which act as tools or services that are available to the programmer
So come on Adam what does that mean in cave man talk. Well to a simple person like me it would be like going to a McDonalds drive through with no queue and everything just waiting to be given to you. Still not making sense? Okay to me it is the fastest way you can possible achieve the specific answer you are looking for. So yeah maybe I could have downloaded some software to run this for me, but trust unless the program is using an API then this will give you results quicker than the program could. Or like if I was to do this manually, just the processing power and memory that firefox.exe uses on my laptop, it would be slower going via the web than it would for me to make the API call, the result is instant. I know not everyone out there has a 10 year old crappy x86 laptop to do all this experimenting on, but trust if it runs super fast on my laptop (which it does) it should be lightning fast on your nice x64 solid state drive stupid amount of ram machine. In a nutshell that is why to use an API for the task, and secondly to my knowledge APIs are normally only serving one purpose to keep them super fast. By one purpose I mean an API to find train times...It is not going to tell you what the weather will be like, or the services available on each train, it will just give you train times. I hope this paragraph has maybe made more sense than the official wiki guide above.
#
Find-CrimeUK 🚨
As I want to find out information about crimes that had happened. Find seemed like the best choice of verb to use.
Find (fd) Looks for an object in a container that is unknown, implied, optional, or specified.
Remember if you are unsure of what verb you can use, or what verb you should use, then please check out the link below for full explanation.
#
Top Tip Add Decent Help 📝
Due to me not adding decent help on more than one occasion. I am now determined to make sure I include decent help to allow the average person like myself to understand how to get using the module in as little time as possible.
NAME
Find-CrimeUK
SYNOPSIS
UK Police API
SYNTAX
Find-CrimeUK [-LocationName] <String> -Year <String> -Month <String> [<CommonParameters>]
DESCRIPTION
Do you like to fight crime? Okay how about do you like to find crime? Well now you can, maybe you want to know how much crime is in your area, maybe you looking to move to a new place in the UK but do not know the local crime scene. Maybe you a gangster and want to see how little crime there is in a given area to then go cause some mayhem. Well what-ever your reasons, you too can now be a crime investigator, by finding crime and the outcome if the police have bothered to update it. Finally for me this was amazing to see all the unsolved crime in my area, broken Britain at its best.
PARAMETERS
-LocationName <String>
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Year <String>
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Month <String>
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Information on crime in the UK from the UK Police API
-------------------------- EXAMPLE 1 --------------------------
PS > Find-CrimeUK -Town Gosport -Year 2022 -Month 02
-------------------------- EXAMPLE 2 --------------------------
PS > Find-CrimeUK -City Portsmouth -Year 2022 -Month 03
-------------------------- EXAMPLE 3 --------------------------
PS > Find-CrimeUK -LocationName Bridgemary -Year 2020 -Month 01
Doh! I just noticed I did not include specific help for each parameter. So maybe I should just write that now, to justify this human error. So this time I decided to give the -LocationName parameter a few alias names City, Town and Village just figured these alias names for the LocationName parameter might make more sense to you depending on where you live. Next the -Year parameter has a validate set parameter, as this API has not been around all that long I figured a paramter validate set would be best to use to force the end-user to only select one of three different years. Lastly the -Month parameter needed the month to be entered in a two digit format. Again to avoid human error I decided a validate set was best to use for this parameter, again forcing the end-user using this to select a correct value that would be accepted by the API.
Attention
Yes this is only available to people in the UK. So this will not bring back information for other countries just the UK, and from reading the API Scotland is not included.
#
I hope you had fun 👋
Hopefully this module will make you think about what you can do with an API. As always I like to try and keep things interesting, and to try and make something unique and useful as the end module product.