latest revision
- If more than one URL is found for the platform, then select the one with the highest revision
This commit is contained in:
parent
9dbcd4521b
commit
7373b01696
1 changed files with 23 additions and 13 deletions
36
upd.py
36
upd.py
|
|
@ -1,6 +1,7 @@
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
@ -36,8 +37,25 @@ async def send_request(json_data):
|
||||||
data = await response.text()
|
data = await response.text()
|
||||||
soup = BeautifulSoup(data, 'html.parser')
|
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
|
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}')
|
print(f'Ответ от GAS: {system_response}')
|
||||||
|
|
||||||
|
def get_urls(find_url):
|
||||||
|
platform_urls = {}
|
||||||
|
version_pattern = re.compile(r'-([0-9]+)\.(exe|tbz)')
|
||||||
|
|
||||||
|
for url, platform in find_url:
|
||||||
|
match = version_pattern.search(str(url))
|
||||||
|
if match:
|
||||||
|
version_number = int(match.group(1))
|
||||||
|
if platform in platform_urls:
|
||||||
|
# Сравниваем и сохраняем URL (если найдено больше одного url для платформы, то выбираем с самой большой ревизией)
|
||||||
|
current_version = int(version_pattern.search(platform_urls[platform]).group(1))
|
||||||
|
if version_number > current_version:
|
||||||
|
platform_urls[platform] = str(url)
|
||||||
|
else:
|
||||||
|
platform_urls[platform] = str(url)
|
||||||
|
|
||||||
|
return platform_urls
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
start_number = 0
|
start_number = 0
|
||||||
|
|
@ -73,18 +91,10 @@ async def main():
|
||||||
find_url.append(result)
|
find_url.append(result)
|
||||||
|
|
||||||
if find_url:
|
if find_url:
|
||||||
platform_urls = {}
|
latest_urls = get_urls(find_url)
|
||||||
for item in find_url:
|
latest_urls["version"] = version
|
||||||
if isinstance(item, tuple):
|
latest_urls["source"] = source
|
||||||
url, platform_name = item
|
req_ver = json.dumps(latest_urls, ensure_ascii=False, indent=2)
|
||||||
if platform_name not in platform_urls:
|
|
||||||
platform_urls[platform_name] = str(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} отправлена')
|
print(f'Версия {version} отправлена')
|
||||||
await send_request(req_ver)
|
await send_request(req_ver)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue