PSCovid19Stats.psm1

function Get-CovidCountriesStats {

    <#
        .SYNOPSIS
        Command used to extract data (Country Stats) from the NovelCOVID API (github.com/NovelCOVID/API)
     
        .DESCRIPTION
        Command used to extract data (Country Stats) from the NovelCOVID API (github.com/NovelCOVID/API)
        Returns data of all countries that has COVID-19
     
        .INPUTS
        None. You cannot pipe objects to Get-CovidCountryStats
     
        .OUTPUTS
        System.String. Get-CovidCountriesStats returns a string with all of the Covid-19 stats for every
        country affected
     
        .EXAMPLE
        PS C:\GitRepos> Get-CovidCountriesStats | Format-Table -AutoSize
        DeathsPerOneMillion TodayCases CasesPerOneMillion Deaths Critical Active Recovered Country TodayDeaths Cases
        ------------------- ---------- ------------------ ------ -------- ------ --------- ------- ----------- -----
        0.07 0 0.5 1 0 6 0 Zimbabwe 0 7
        0 1 2 0 0 29 0 Zambia 0 29
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidCountriesStats
     
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com/
        LinkedIn: https://www.linkedin.com/in/lukeleigh/
        GitHub: https://github.com/BanterBoy/
        GitHubGist: https://gist.github.com/BanterBoy
     
    #>


    BEGIN {

    }

    PROCESS {
        $CountriesHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $CountriesHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $CountriesResponses = Invoke-RestMethod 'https://corona.lmao.ninja/countries?sort=country' -Method 'GET' -Headers $CountriesHeaders -Body $body

        foreach ($Response in $CountriesResponses) {
            try {
                $properties = @{
                    Country             = [string]$Response.country
                    TodayCases          = [int]$Response.todayCases
                    TodayDeaths         = [int]$Response.todayDeaths
                    Cases               = [int]$Response.cases
                    Active              = [int]$Response.active
                    Critical            = [int]$Response.critical
                    Deaths              = [int]$Response.deaths
                    Recovered           = [int]$Response.recovered
                    CasesPerOneMillion  = [decimal]$Response.casesPerOneMillion
                    DeathsPerOneMillion = [decimal]$Response.deathsPerOneMillion
                }
            }
            catch {
                $properties = @{
                    Country             = [string]$Response.country
                    TodayCases          = [int]$Response.todayCases
                    TodayDeaths         = [int]$Response.todayDeaths
                    Cases               = [int]$Response.cases
                    Active              = [int]$Response.active
                    Critical            = [int]$Response.critical
                    Deaths              = [int]$Response.deaths
                    Recovered           = [int]$Response.recovered
                    CasesPerOneMillion  = [decimal]$Response.casesPerOneMillion
                    DeathsPerOneMillion = [decimal]$Response.deathsPerOneMillion
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}

function Get-CovidCountryStats {

    <#
        .SYNOPSIS
        Command used to extract data (Country Stats) from the NovelCOVID API (github.com/NovelCOVID/API)
     
        .DESCRIPTION
        Command used to extract data (Country Stats) from the NovelCOVID API (github.com/NovelCOVID/API)
        Returns data of a specific country.
     
        .PARAMETER Country
        This is a mandatory field which you can enter manually or using tab to cycle through the options.
        This field uses the standard [ISO Country Codes](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes)
     
        .INPUTS
        None. You cannot pipe objects to Get-CovidCountryStats
     
        .OUTPUTS
        System.String. Get-CovidCountriesStats returns a string with all of the Covid-19 stats for the
        specified country.
     
        .EXAMPLE
        PS C:\GitRepos> Get-CovidCountryStats -Country UK
         
        DeathsPerOneMillion : 18
        TodayCases : 2433
        CasesPerOneMillion : 288
        Deaths : 1228
        Critical : 163
        Active : 18159
        Recovered : 135
        Country : UK
        TodayDeaths : 209
        Cases : 19522
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidCountryStats
     
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com/
        LinkedIn: https://www.linkedin.com/in/lukeleigh/
        GitHub: https://github.com/BanterBoy/
        GitHubGist: https://gist.github.com/BanterBoy
     
    #>


    [CmdletBinding(DefaultParameterSetName = 'ParameterSet1',
        SupportsShouldProcess = $false,
        PositionalBinding = $false,
        HelpUri = 'https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidCountryStats',
        ConfirmImpact = 'Medium')]
    param(
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ParameterSetName = 'ParameterSet1')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [OutputType([String])]
        [ArgumentCompleter( { 'AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'AN', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW' }) ]
        [string]
        $Country
    )

    BEGIN {
    }
    
    PROCESS {
        $CountryHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $CountryHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $CountryResponse = Invoke-RestMethod "https://corona.lmao.ninja/countries/$Country" -Method 'GET' -Headers $CountryHeaders -Body $body
        
        foreach ($Response in $CountryResponse) {
            try {
                $properties = @{
                    Country             = [string]$Response.country
                    TodayCases          = [int]$Response.todayCases
                    TodayDeaths         = [int]$Response.todayDeaths
                    Cases               = [int]$Response.cases
                    Active              = [int]$Response.active
                    Critical            = [int]$Response.critical
                    Deaths              = [int]$Response.deaths
                    Recovered           = [int]$Response.recovered
                    CasesPerOneMillion  = [decimal]$Response.casesPerOneMillion
                    DeathsPerOneMillion = [decimal]$Response.deathsPerOneMillion
                }
            }
            catch {
                $properties = @{
                    Country             = [string]$Response.country
                    TodayCases          = [int]$Response.todayCases
                    TodayDeaths         = [int]$Response.todayDeaths
                    Cases               = [int]$Response.cases
                    Active              = [int]$Response.active
                    Critical            = [int]$Response.critical
                    Deaths              = [int]$Response.deaths
                    Recovered           = [int]$Response.recovered
                    CasesPerOneMillion  = [decimal]$Response.casesPerOneMillion
                    DeathsPerOneMillion = [decimal]$Response.deathsPerOneMillion
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}

function Get-CovidHistoricalData {

    <#
        .SYNOPSIS
        Command used to extract historical data from the NovelCOVID API (github.com/NovelCOVID/API)
 
        .DESCRIPTION
        Command used to extract historical data from the NovelCOVID API (github.com/NovelCOVID/API)
 
        .INPUTS
        None. You cannot pipe objects to Get-CovidHistoricalData
 
        .OUTPUTS
        System.String. Get-CovidHistoricalData returns a string with all of the Covid-19 stats for every
        country affected
 
        .EXAMPLE
        PS C:\GitRepos> Get-CovidHistoricalData
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidHistoricalData
 
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com
        LinkedIn: https://www.linkedin.com/in/lukeleigh
        GitHub: https://github.com/BanterBoy
        GitHubGist: https://gist.github.com/BanterBoy
    #>


    BEGIN {
    
    }

    PROCESS {
        $HistoricalDataHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $HistoricalDataHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $HistoricalData = Invoke-RestMethod 'https://corona.lmao.ninja/v2/historical' -Method 'GET' -Headers $HistoricalDataHeaders -Body $body

        foreach ($Data in $HistoricalData) {
            try {
                $properties = @{
                    country  = $Data.country
                    province = $Data.province
                    Cases    = $HistoricalData[0].timeline.cases
                    Deaths   = $HistoricalData[0].timeline.deaths
                }
            }
            catch {
                $properties = @{
                    country  = $Data.country
                    province = $Data.province
                    Cases    = $HistoricalData[0].timeline.cases
                    Deaths   = $HistoricalData[0].timeline.deaths
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}

function Get-CovidjhucsseData {

    <#
 
        .SYNOPSIS
        Command used to extract John HOpkins CSSE Data from the NovelCOVID API (github.com/NovelCOVID/API)
 
        .DESCRIPTION
        Command used to extract John HOpkins CSSE Data from the NovelCOVID API (github.com/NovelCOVID/API)
        Return data from the John Hopkins CSSE Data Repository (Provinces and such).
 
        .INPUTS
        None. You cannot pipe objects to Get-CovidjhucsseData
 
        .OUTPUTS
        System.String. Get-CovidjhucsseData returns a string with all of the Covid-19 stats for every
        country affected
 
        .EXAMPLE
        PS C:\GitRepos> Get-CovidjhucsseData
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidjhucsseData
 
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com
        LinkedIn: https://www.linkedin.com/in/lukeleigh
        GitHub: https://github.com/BanterBoy
        GitHubGist: https://gist.github.com/BanterBoy
 
#>



    BEGIN {
    
    }

    PROCESS {
        $jhucsseDataHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $jhucsseDataHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $jhucsseData = Invoke-RestMethod 'https://corona.lmao.ninja/jhucsse' -Method 'GET' -Headers $jhucsseDataHeaders -Body $body

        foreach ($jhucsse in $jhucsseData) {
            try {
                $properties = @{
                    City      = [string]$jhucsse.city
                    Province  = [string]$jhucsse.province
                    Country   = [string]$jhucsse.country
                    UpdatedAt = [datetime]$jhucsse.updatedAt
                    Longitude = $jhucsse.coordinates.longitude
                    Latitude  = $jhucsse.coordinates.latitude
                    Confirmed = $jhucsse.stats.confirmed
                    Recovered = $jhucsse.stats.recovered
                    Deaths    = $jhucsse.stats.deaths
                }
            }
            catch {
                $properties = @{
                    City      = [string]$jhucsse.city
                    Province  = [string]$jhucsse.province
                    Country   = [string]$jhucsse.country
                    UpdatedAt = [datetime]$jhucsse.updatedAt
                    Longitude = $jhucsse.coordinates.longitude
                    Latitude  = $jhucsse.coordinates.latitude
                    Confirmed = $jhucsse.stats.confirmed
                    Recovered = $jhucsse.stats.recovered
                    Deaths    = $jhucsse.stats.deaths
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}

function Get-CovidStateStats {

    <#
 
        .SYNOPSIS
        Command used to extract Data for all US States from the NovelCOVID API (github.com/NovelCOVID/API)
 
        .DESCRIPTION
        Command used to extract John HOpkins CSSE Data from the NovelCOVID API (github.com/NovelCOVID/API)
        Return data from the John Hopkins CSSE Data Repository (Provinces and such).
 
        .INPUTS
        None. You cannot pipe objects to Get-CovidStateStats
 
        .OUTPUTS
        System.String. Get-CovidStateStats returns a string with all of the Covid-19 stats for all US States
 
        .EXAMPLE
        PS C:\GitRepos> Get-CovidStateStats
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidStateStats
 
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com
        LinkedIn: https://www.linkedin.com/in/lukeleigh
        GitHub: https://github.com/BanterBoy
        GitHubGist: https://gist.github.com/BanterBoy
 
    #>



    BEGIN {
        
    }
    
    PROCESS {
        $StateHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $StateHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $StateResponses = Invoke-RestMethod 'https://corona.lmao.ninja/states' -Method 'GET' -Headers $StateHeaders -Body $body
        
        foreach ($Response in $StateResponses) {
            try {
                $properties = @{
                    State       = [string]$Response.state
                    TodayCases  = [int]$Response.todayCases
                    TodayDeaths = [int]$Response.todayDeaths
                    Cases       = [int]$Response.cases
                    Active      = [int]$Response.active
                    Deaths      = [int]$Response.deaths
                }
            }
            catch {
                $properties = @{
                    State       = [string]$Response.state
                    TodayCases  = [int]$Response.todayCases
                    TodayDeaths = [int]$Response.todayDeaths
                    Cases       = [int]$Response.cases
                    Active      = [int]$Response.active
                    Deaths      = [int]$Response.deaths
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}

function Get-CovidWorldStats {

    <#
 
        .SYNOPSIS
        Command used to extract Data for all Returns all total cases, recovery, and deaths from the NovelCOVID API (github.com/NovelCOVID/API)
 
        .DESCRIPTION
        Command used to extract John HOpkins CSSE Data from the NovelCOVID API (github.com/NovelCOVID/API)
        Returns all total cases, recovery, and deaths.
 
        .INPUTS
        None. You cannot pipe objects to Get-CovidWorldStats
 
        .OUTPUTS
        System.String. Get-CovidWorldStats returns a string of all total cases, recovery, and deaths.
 
        .EXAMPLE
        PS C:\GitRepos> Get-CovidWorldStats
        Active : 536625
        Recovered : 151312
        Deaths : 33966
        Cases : 721903
        Updated : 30/03/2020 02:08:07
 
        .LINK
        https://github.com/BanterBoy/PSCovid19Stats/wiki/Get-CovidWorldStats
 
        .NOTES
        Author: Luke Leigh
        Website: https://blog.lukeleigh.com
        LinkedIn: https://www.linkedin.com/in/lukeleigh
        GitHub: https://github.com/BanterBoy
        GitHubGist: https://gist.github.com/BanterBoy
 
    #>



    BEGIN {
    
    }

    PROCESS {
        $AllHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $AllHeaders.Add("Cookie", "__cfduid=d6907f091c38e985d84bd05e1faf548a61585349147")
        $AllResponses = Invoke-RestMethod 'https://corona.lmao.ninja/all' -Method 'GET' -Headers $AllHeaders -Body $body
        $EpochStart = Get-Date "01/01/1970 00:00:00"

        foreach ($Response in $AllResponses) {
            try {
                $properties = @{
                    Cases     = $Response.cases
                    Deaths    = $Response.Deaths
                    Recovered = $Response.Recovered
                    Updated   = $EpochStart.AddMilliseconds($Response.Updated)
                    Active    = $Response.Active
                }
            }
            catch {
                $properties = @{
                    Cases     = $Response.cases
                    Deaths    = $Response.Deaths
                    Recovered = $Response.Recovered
                    Updated   = $EpochStart.AddMilliseconds($Response.Updated)
                    Active    = $Response.Active
                }
            }
            finally {
                $obj = New-Object -TypeName PSObject -Property $Properties
                Write-Output $obj
            }
        }
    }

    END {

    }

}