added workflows

This commit is contained in:
amd64fox 2023-06-19 17:17:58 +03:00
parent d28b01fde0
commit 3ea6da3258
3 changed files with 125 additions and 0 deletions

23
.github/workflows/main.yml vendored Normal file
View file

@ -0,0 +1,23 @@
name: Version Check
on:
repository_dispatch:
types: [webhook-event]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Python script
run: python ${{ github.workspace }}/upd.py -v ${{ github.event.client_payload.v }} -s "${{ github.event.client_payload.s }}" -u "${{ secrets.GOOGLE_APPS_URL }}"

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
aiohttp
asyncio
beautifulsoup4
argparse

98
upd.py Normal file
View file

@ -0,0 +1,98 @@
import aiohttp
import asyncio
import json
import argparse
from bs4 import BeautifulSoup
parser = argparse.ArgumentParser()
parser.add_argument('-v', required=True)
parser.add_argument('-s', required=True)
parser.add_argument('-u', required=True)
args = parser.parse_args()
version = args.v
source = args.s
u = args.u
async def check_url(session, url, platform_name):
try:
async with session.get(url) as response:
if response.status == 200:
if platform_name:
return response.url, platform_name
else:
return response.url
except aiohttp.ClientError:
pass
return None
async def send_request(json_data):
url = u + json_data
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
data = await response.text()
soup = BeautifulSoup(data, 'html.parser')
system_response = soup.find('div', style='text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px').text
print(f'Ответ от Google apps script: {system_response}')
async def main():
start_number = 0
before_enter = 4500
numbers = start_number
find_url = []
win32 = "https://upgrade.scdn.co/upgrade/client/win32-x86/spotify_installer-{version}-{numbers}.exe"
win_arm64 = "https://upgrade.scdn.co/upgrade/client/win32-arm64/spotify_installer-{version}-{numbers}.exe"
osx = "https://upgrade.scdn.co/upgrade/client/osx-x86_64/spotify-autoupdate-{version}-{numbers}.tbz"
osx_arm64 = "https://upgrade.scdn.co/upgrade/client/osx-arm64/spotify-autoupdate-{version}-{numbers}.tbz"
async with aiohttp.ClientSession() as session:
tasks = []
url_templates = [win32, win_arm64, osx, osx_arm64]
platform_names = ["WIN32", "WIN-ARM64", "OSX", "OSX-ARM64"]
for url_template, platform_name in zip(url_templates, platform_names):
numbers = start_number
while numbers <= before_enter:
url = url_template.format(
version=version, numbers=numbers
)
tasks.append(check_url(session, url, platform_name))
numbers += 1
results = []
for task in asyncio.as_completed(tasks):
result = await task
if result is not None:
find_url.append(result)
if find_url:
platform_urls = {}
for item in find_url:
if isinstance(item, tuple):
url, platform_name = item
if platform_name not in platform_urls:
platform_urls[platform_name] = str(url) # Преобразование URL в строку
else:
if "unknown" not in platform_urls:
platform_urls["unknown"] = "unknown"
platform_urls["version"] = version
platform_urls["source"] = source
req_ver = json.dumps(platform_urls)
print(f'Версия {version} отправлена')
await send_request(req_ver)
else:
print(f'Версия {version} не найдена')
data = {
"unknown": "unknown",
"version": version
}
req_ver = json.dumps(data)
await send_request(req_ver)
asyncio.run(main())