Загрузка данных


@echo off
setlocal EnableExtensions EnableDelayedExpansion

set "URL=https://kompege.ru"

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$url = '%URL%'; ^
$desktop = [Environment]::GetFolderPath('Desktop'); ^
$projects = Join-Path $desktop 'Projects'; ^
if (!(Test-Path $projects)) { New-Item -ItemType Directory -Path $projects | Out-Null }; ^
$today = Get-Date -Format 'yyyy-MM-dd'; ^
$n = 1; ^
do { $pyFile = Join-Path $projects ($today + '_' + $n + '.py'); $n++ } while (Test-Path $pyFile); ^
New-Item -ItemType File -Path $pyFile | Out-Null; ^
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class Win {
    [DllImport(""user32.dll"")]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
}
'@; ^
Add-Type -AssemblyName System.Windows.Forms; ^
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea; ^
$halfW = [int]($screen.Width / 2); ^
$h = [int]$screen.Height; ^
$chromeStart = Get-Date; ^
Start-Process 'chrome.exe' -ArgumentList ('--new-window ' + $url); ^
Start-Sleep -Seconds 2; ^
$chrome = Get-Process chrome -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Sort-Object StartTime -Descending | Select-Object -First 1; ^
if ($chrome) { [Win]::MoveWindow($chrome.MainWindowHandle, 0, 0, $halfW, $h, $true) | Out-Null }; ^
$idleStart = Get-Date; ^
$opened = $false; ^
foreach ($cmd in @('pyw.exe','pythonw.exe','python.exe')) { ^
    if (!$opened -and (Get-Command $cmd -ErrorAction SilentlyContinue)) { ^
        Start-Process $cmd -ArgumentList @('-m','idlelib', $pyFile); ^
        $opened = $true; ^
    } ^
}; ^
if (!$opened) { Start-Process notepad.exe $pyFile }; ^
Start-Sleep -Seconds 3; ^
$idleProc = Get-Process pythonw,python,pyw -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Sort-Object StartTime -Descending | Select-Object -First 1; ^
if ($idleProc) { [Win]::MoveWindow($idleProc.MainWindowHandle, $halfW, 0, $halfW, $h, $true) | Out-Null }"

endlocal