Skip to content

Commit

Permalink
Fix download via HTTP/2
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jan 1, 2024
1 parent 1e3851c commit c3c163a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand Down
23 changes: 13 additions & 10 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@
from pathlib import Path

_hdr = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'
'Sec-Fetch-Site': 'none',
'Accept-Encoding': 'identity',
'Sec-Fetch-Mode': 'navigate',
'Host': 'www.st.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15',
'Accept-Language': 'en-GB,en;q=0.9',
'Sec-Fetch-Dest': 'document',
'Connection': 'keep-alive',
}

def download_svd_data():
url = "https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/"
url += "stm32-32-bit-arm-cortex-mcus.cxst-rs-grid.html/CL1734.cad_models_and_symbols.svd.json"
with urlopen(Request(url, headers=_hdr)) as data:
json_data = data.read().decode(encoding="utf-8", errors="ignore")
cmd = f"curl '{url}' -L -s --max-time 60 -o - " + " ".join(f"-H '{k}: {v}'" for k,v in _hdr.items())
data = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE).stdout
json_data = data.decode(encoding="utf-8", errors="ignore")
rows = json.loads(json_data)["rows"]
return [(row["localizedDescriptions"]["en"].split(" ")[0], row["version"],
"https://www.st.com" + row["localizedLinks"]["en"]) for row in rows]

def download_zip(url, path):
if path.exists(): path.unlink()
with tempfile.NamedTemporaryFile() as outfile:
os.system(f'wget -q --user-agent="{_hdr["User-Agent"]}" "{url}" -O {outfile.name}')
shutil.copy(outfile.name, str(path))
cmd = f"curl '{url}' -L -s --max-time 60 -o {path} " + " ".join(f"-H '{k}: {v}'" for k,v in _hdr.items())
assert subprocess.call(cmd, shell=True) == 0


def download_families(download = True):
Expand Down

0 comments on commit c3c163a

Please sign in to comment.