Skip to content

Commit 657508e

Browse files
committed
Changed the scraper to scrape the module indexes. Added metadata function to user API
1 parent 38a7853 commit 657508e

File tree

13 files changed

+1891
-1327
lines changed

13 files changed

+1891
-1327
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
recursive-include stdlib_list/lists *.txt
1+
recursive-include stdlib_list/lists *.csv
22
include README.rst

stdlib_list/__init__.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from _version import __version__
22

33
import os
4+
import csv
45

56

67
long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3"]
@@ -21,15 +22,53 @@ def get_canonical_version(version):
2122
return version
2223

2324

24-
def stdlib_list(version):
25+
def metadata(version):
2526

2627
version = get_canonical_version(version)
2728

28-
lib_file = os.path.join(data_dir, "{}.txt".format(version))
29+
lib_file = os.path.join(data_dir, "{}.csv".format(version))
30+
31+
result = {}
2932

3033
with open(lib_file) as f:
31-
result = [x.strip() for x in f.readlines()]
34+
reader = csv.DictReader(f)
35+
36+
for row in reader:
37+
module = row["module"]
38+
result[module] = {
39+
x: row[x]
40+
for x in ["os", "description", "deprecated"]
41+
}
42+
43+
if result[module]["deprecated"] == "":
44+
result[module]["deprecated"] = None
45+
else:
46+
result[module]["deprecated"] = int(
47+
result[module]["deprecated"])
3248

3349
return result
3450

51+
52+
def stdlib_list(version, os=None, deprecated=None,
53+
max_module_level=None):
54+
55+
module_data = metadata(version)
56+
57+
if os:
58+
module_data = {x: y for x, y in module_data.items() if y["os"] == os}
59+
60+
if deprecated is not None:
61+
module_data = {
62+
x: y for x, y in module_data.items()
63+
if bool(y["deprecated"]) == bool(deprecated)
64+
}
65+
66+
if max_module_level:
67+
module_data = {
68+
x: y for x, y in module_data.items()
69+
if len(x.split(".")) <= max_module_level
70+
}
71+
72+
return sorted(module_data.keys())
73+
3574
import scraper

stdlib_list/lists/2.6.csv

Lines changed: 425 additions & 0 deletions
Large diffs are not rendered by default.

stdlib_list/lists/2.6.txt

Lines changed: 0 additions & 283 deletions
This file was deleted.

0 commit comments

Comments
 (0)