diff --git a/README.md b/README.md index e2af47c..0b0c962 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,13 @@ brew tap bash/homebrew-coop brew install --HEAD coop ``` +### Installation on Windows +coop is avaible as a powershell module: + +```powershell +Invoke-WebRequest -OutFile CoopInstaller.ps1 -Uri https://raw.githubusercontent.com/STJEREM/coop/development/client/powershell/Installer.ps1; .\CoopInstaller.ps1 "0.0.3" +``` + ## API The api is hosted at [themachine.jeremystucki.com](https://themachine.jeremystucki.com). diff --git a/client/coop.ps1 b/client/coop.ps1 deleted file mode 100644 index 79adb21..0000000 --- a/client/coop.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -param ( - [switch] $Version, - [string] $location = "", - [string] $menuFilter = "" -) - -function Get-Unix-Midnight() { - return [int][double]::Parse($(Get-Date -date (Get-Date -Hour 0 -Minute 00 -Second 00 -Millisecond 0000).ToUniversalTime()-uformat %s)) -} - -if ($Version -eq $true) { - Write-Host "STJEREM/coop 0.0.1" -NoNewline - Exit -} - -if ($location -eq "") { - $location = $(Read-Host "Location") -} - -$timestamp = Get-Unix-Midnight - -$client = New-Object System.Net.WebClient -$url = "https://themachine.jeremystucki.com/api/v1/coop/menus/$($location)/$($timestamp)" - -$response = $client.DownloadString($url) -$json = ConvertFrom-Json $response - -Write-Host "" - -foreach ($menu in $json.results) { - if ($menuFilter -ne "" -and $menu.title -ne $menuFilter) { - continue; - } - - Write-Host -NoNewline $menu.title - Write-Host -Foreground Magenta " $($menu.price)" - - foreach($item in $menu.menu) { - Write-Host "- $($item)" - } - - Write-Host "" -} - - -Write-Host "Press [ENTER] key to close ..." -Read-Host \ No newline at end of file diff --git a/client/powershell/Coop/Coop.psd1 b/client/powershell/Coop/Coop.psd1 new file mode 100644 index 0000000..d02127c Binary files /dev/null and b/client/powershell/Coop/Coop.psd1 differ diff --git a/client/powershell/Coop/STJEREM.Coop.ps1 b/client/powershell/Coop/STJEREM.Coop.ps1 new file mode 100644 index 0000000..8e0a5e4 --- /dev/null +++ b/client/powershell/Coop/STJEREM.Coop.ps1 @@ -0,0 +1,49 @@ +function Coop { + [CmdletBinding()] + param ( + [switch] $Version, + [string] $location = "", + [string] $menuFilter = "" + ) + + function Get-Unix-Midnight() { + return [int][double]::Parse($(Get-Date -date (Get-Date -Hour 0 -Minute 00 -Second 00 -Millisecond 0000).ToUniversalTime()-uformat %s)) + } + + if ($Version -eq $true) { + $module = Get-Module Coop + Write-Host "STJEREM/coop $($module.Version)" + Return + } + + if ($location -eq "") { + $location = $(Read-Host "Location") + } + + $timestamp = Get-Unix-Midnight + + $client = New-Object System.Net.WebClient + $url = "https://themachine.jeremystucki.com/api/v1/coop/menus/$($location)/$($timestamp)" + + $response = $client.DownloadString($url) + $json = ConvertFrom-Json $response + + Write-Host "" + + foreach ($menu in $json.results) { + if ($menuFilter -ne "" -and $menu.title -ne $menuFilter) { + continue; + } + + Write-Host -NoNewline $menu.title + Write-Host -Foreground Magenta " $($menu.price)" + + foreach($item in $menu.menu) { + Write-Host "- $($item)" + } + + Write-Host "" + } +} + +Export-ModuleMember -Cmdlet Coop \ No newline at end of file diff --git a/client/powershell/Installer.ps1 b/client/powershell/Installer.ps1 new file mode 100644 index 0000000..f203233 --- /dev/null +++ b/client/powershell/Installer.ps1 @@ -0,0 +1,41 @@ +param ( + [string] $version = (Read-Host "Commit - SHA or Tag") +) + +$url = "https://github.com/STJEREM/coop/archive/$($version).zip" +$out = "$env:TEMP\coop-$($version).zip" +$tmp = "$env:TEMP" +$installDir = "$Home\Documents\WindowsPowerShell\Modules" + +function Expand-ZipFile($file, $destination) { + $shell = New-Object -com shell.application + $zip = $shell.NameSpace($file) + + foreach($item in $zip.items()) { + $shell.Namespace($destination).copyhere($item) + } +} + +Write-Host "Downloading package..." + +Invoke-WebRequest -Uri $url -OutFile $out +Expand-ZipFile $out $tmp + +if ((Test-Path $installDir) -eq $false) { + New-Item -ItemType Directory -Force -Path $installDir | Out-Null +} + +if ((Test-Path "$($installDir)\Coop") -eq $true) { + Write-Host "Removing previous installed version..." + Remove-Item -Force -Recurse "$($installDir)\Coop" +} + +Write-Host "Installing files..." +Copy-Item -Recurse "$($tmp)\coop-$($version)\client\powershell\Coop" $installDir + +Write-Host "Cleaning up..." +Remove-Item -Force $out +Remove-Item -Force -Recurse "$($tmp)\coop-$($version)" + +Write-Host "" +Write-Host -Foreground Green "Installation Successful! Type 'Coop' to see available menus." \ No newline at end of file diff --git a/client/coop b/client/python/coop similarity index 96% rename from client/coop rename to client/python/coop index db8b93b..dfbf78d 100755 --- a/client/coop +++ b/client/python/coop @@ -21,7 +21,7 @@ def print_menu(menu): def print_version(): - print('STJEREM/coop 0.0.2') + print('STJEREM/coop 0.0.3') if len(sys.argv) == 2 and sys.argv[1] == '--version': diff --git a/client/requirements.txt b/client/python/requirements.txt similarity index 100% rename from client/requirements.txt rename to client/python/requirements.txt