|
17 | 17 | import requests |
18 | 18 | import sys |
19 | 19 |
|
| 20 | +import xml.etree.ElementTree as ET |
20 | 21 | from bs4 import BeautifulSoup |
21 | 22 | from tqdm import tqdm |
22 | 23 |
|
|
26 | 27 | "folder": "win", |
27 | 28 | "root": "https://docs.microsoft.com/en-us/openspecs/windows_protocols", |
28 | 29 | "list": "https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-winprotlp/e36c976a-6263-42a8-b119-7a3cc41ddd2a", |
| 30 | + "rss": "https://winprotocoldocs-bhdugrdyduf5h2e4.b02.azurefd.net/", |
29 | 31 | "extras": [ |
30 | 32 | # Protocols not listed in the "list" |
31 | 33 | "ms-dltm", |
|
39 | 41 | "folder": "win", |
40 | 42 | "root": "https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols", |
41 | 43 | "list": "https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxprotlp/229f77ea-6518-4fe7-84fe-bd535fc6c32e", |
| 44 | + "rss": "https://officeprotocoldoc.z19.web.core.windows.net/files/", |
42 | 45 | "extras": [ |
43 | 46 | # Protocols not listed in the "list" |
44 | 47 | "ms-oxcrpc", |
|
49 | 52 | "folder": "win", |
50 | 53 | "root": "https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols", |
51 | 54 | "list": "https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/MS-SPPROTLP/51f9ccbf-ea59-4bb5-9fe6-27bc5af855ff", |
| 55 | + "rss": "https://officeprotocoldoc.z19.web.core.windows.net/files/", |
52 | 56 | }, |
53 | 57 | ] |
54 | 58 |
|
55 | 59 | DEFAULT = "DEFAULT" |
56 | 60 |
|
57 | 61 |
|
| 62 | +def get_version(VERSION_URL, protocol): |
| 63 | + """ |
| 64 | + Get the version + date of the current online protocol. |
| 65 | + """ |
| 66 | + rss = requests.get( |
| 67 | + VERSION_URL + protocol.upper() + "/[" + protocol.upper() + "].rss" |
| 68 | + ).content |
| 69 | + root = ET.fromstring(rss) |
| 70 | + item = root.find("channel").find("item") |
| 71 | + version = re.search(r"\(Version ([0-9.]+)\)", item.find("title").text).group(1) |
| 72 | + pubdate = item.find("pubDate").text |
| 73 | + return version, pubdate |
| 74 | + |
| 75 | + |
58 | 76 | def get_protocol_list(TECHNICAL_DOCS_URL): |
59 | 77 | """ |
60 | 78 | Fetch the list of protocol names from Microsoft's technical documents page. |
@@ -171,6 +189,9 @@ def download_protocol_idls(protocol_name, entry, output): |
171 | 189 | """ |
172 | 190 | num_files_saved = 0 |
173 | 191 |
|
| 192 | + # 0. Get IDL version |
| 193 | + version, pubdate = get_version(entry["rss"], protocol_name) |
| 194 | + |
174 | 195 | # 1. Get potential IDL URLs |
175 | 196 | idl_urls = get_idl_urls(protocol_name, entry["root"]) |
176 | 197 | if not idl_urls: |
@@ -198,6 +219,16 @@ def download_protocol_idls(protocol_name, entry, output): |
198 | 219 | # Write it to disk |
199 | 220 | with open(output / file_name, "w") as f: |
200 | 221 | try: |
| 222 | + # Write header |
| 223 | + f.write( |
| 224 | + "// [%s] v%s (%s)\n" |
| 225 | + % ( |
| 226 | + protocol_name, |
| 227 | + version, |
| 228 | + pubdate, |
| 229 | + ) |
| 230 | + ) |
| 231 | + # Write content |
201 | 232 | f.write(idl_file) |
202 | 233 | num_files_saved += 1 |
203 | 234 | except (TypeError, AttributeError) as e: |
|
0 commit comments