mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 09:25:33 +00:00
48 lines
1.5 KiB
Python
Executable file
48 lines
1.5 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
from bs4 import BeautifulSoup
|
|
import datetime
|
|
import logging
|
|
import requests
|
|
import requests_cache
|
|
import os
|
|
import time
|
|
from keyman_config.get_kmp import keyman_cache_dir
|
|
|
|
def get_keyboard_dir_page(kb_url):
|
|
logging.info("Getting keyboard list")
|
|
logging.debug("At URL %s", kb_url)
|
|
cache_dir = keyman_cache_dir()
|
|
current_dir = os.getcwd()
|
|
expire_after = datetime.timedelta(days=7)
|
|
if not os.path.isdir(cache_dir):
|
|
os.makedirs(cache_dir)
|
|
os.chdir(cache_dir)
|
|
requests_cache.install_cache(cache_name='keyman_cache', backend='sqlite', expire_after=expire_after)
|
|
now = time.ctime(int(time.time()))
|
|
response = requests.get(kb_url)
|
|
logging.debug("Time: {0} / Used Cache: {1}".format(now, response.from_cache))
|
|
os.chdir(current_dir)
|
|
requests_cache.core.uninstall_cache()
|
|
if response.status_code == 200:
|
|
return response.text
|
|
else:
|
|
return None
|
|
|
|
|
|
def get_dir_list():
|
|
url = "https://downloads.keyman.com/keyboards/"
|
|
page = get_keyboard_dir_page(url)
|
|
# print(page)
|
|
soup = BeautifulSoup(page, 'html.parser')
|
|
# return [url + '/' + node.get('href') for node in soup.find_all('a') if node.get('href').endswith(ext)]
|
|
return [url + node.get('href') for node in soup.find_all('a')]
|
|
|
|
def list_keyboards():
|
|
kblist = []
|
|
for file in get_dir_list():
|
|
logging.debug(file)
|
|
kb = os.path.basename(os.path.dirname(file))
|
|
if kb != "keyboards":
|
|
kblist.append(kb)
|
|
return kblist
|