[Python]一个下载OpenGL所有官方文档的Python脚本

可以下载的OpenGL资源包含(可修改脚本中的配置下载全部或者部分):

  • OpenGL的API说明文档
  • OpenGL的Reference Card
  • OpenGL ES的API说明文档
  • OpenGL ES的Reference Card
#!/usr/bin/python
#coding=utf-8


import urllib.request
import re
import os


# OpenGL Reference Card URL
OPENGL_REF_URL0  = "https://www.khronos.org/developers/reference-cards/"

# OpenGL Reference Card Download URL
OPENGL_REF_URL1   = "https://www.khronos.org/files/"

# OpenGL Registry URL
OPENGL_REG_URL   = "https://www.khronos.org/registry/OpenGL/specs/"
OPENGLGL_REG_URL = "https://www.khronos.org/registry/OpenGL/specs/gl/"
OPENGLES_REG_URL = "https://www.khronos.org/registry/OpenGL/specs/es/"
OPENGLSC_REG_URL = "https://www.khronos.org/registry/OpenGL/specs/sc/"

# which type of OpenGL Resource do u want to download?
OPENGL_URL = OPENGLES_REG_URL

# download configurations
DOWNLOAD_ENABLE = True
DOWNLOAD_TOOL   = "axel"
DOWNLOAD_TNUM   = 20
DOWNLOAD_TO     = os.path.expanduser('~') + "/Downloads/OpenGL_Resources/"


def listOpenGLRegistryUrl(url):
    content = urllib.request.urlopen(url).read()
    content = content.decode('utf-8')

    reg = r'\\\[(...)\]'
    pattern = re.compile(reg)
    suburls = re.findall(pattern, content)

    for item in suburls:
        if item[1] == "DIR":
            listOpenGLRegistryUrl(url + item[0])
        if item[1] == "   ":
            if DOWNLOAD_ENABLE:
                download(url + item[0])
            print(url + item[0])


def listOpenGLRefCardUrl(url):
    content = urllib.request.urlopen(url).read()
    content = content.decode('utf-8')

    reg = r'\

你可能感兴趣的:([Python]一个下载OpenGL所有官方文档的Python脚本)