Skip to content

Commit 1558d25

Browse files
committed
Improve examples on the readme file
1 parent c30c562 commit 1558d25

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

README.md

+22-25
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,52 @@
1818
# Usage
1919

2020
```python
21-
>>> from pprint import pprint
22-
>>> import scrapedict as sd
23-
>>> from urllib.request import urlopen
21+
import scrapedict as sd
22+
from urllib.request import urlopen
2423

2524
# Fetch the content from the Urban Dictionary page for "larping"
26-
>>> url = "https://www.urbandictionary.com/define.php?term=larping"
27-
>>> content = urlopen(url).read().decode()
25+
url = "https://www.urbandictionary.com/define.php?term=larping"
26+
content = urlopen(url).read().decode()
2827

2928
# Define the fields to be extracted
30-
>>> fields = {
31-
... "word": sd.text(".word"),
32-
... "meaning": sd.text(".meaning"),
33-
... "example": sd.text(".example"),
34-
... }
29+
fields = {
30+
"word": sd.text(".word"),
31+
"meaning": sd.text(".meaning"),
32+
"example": sd.text(".example"),
33+
}
3534

3635
# Extract the data using scrapedict
37-
>>> item = sd.extract(fields, content)
36+
item = sd.extract(fields, content)
3837

3938
# The result is a dictionary with the word, its meaning, and an example usage.
4039
# Here, we perform a couple of assertions to demonstrate the expected structure and content.
41-
>>> assert isinstance(item, dict)
42-
>>> assert item["word"] == "Larping"
43-
40+
assert isinstance(item, dict)
41+
assert item["word"] == "Larping"
4442
```
4543

4644

4745
# The orange site example
4846

4947
```python
50-
>>> import scrapedict as sd
51-
>>> from urllib.request import urlopen
48+
import scrapedict as sd
49+
from urllib.request import urlopen
5250

5351
# Fetch the content from the Hacker News homepage
54-
>>> url = "https://news.ycombinator.com/"
55-
>>> content = urlopen(url).read().decode()
52+
url = "https://news.ycombinator.com/"
53+
content = urlopen(url).read().decode()
5654

5755
# Define the fields to extract: title and URL for each news item
58-
>>> fields = {
59-
... "title": sd.text(".titleline a"),
60-
... "url": sd.attr(".titleline a", "href"),
61-
... }
56+
fields = {
57+
"title": sd.text(".titleline a"),
58+
"url": sd.attr(".titleline a", "href"),
59+
}
6260

6361
# Use scrapedict to extract all news items as a list of dictionaries
64-
>>> items = sd.extract_all(".athing", fields, content)
62+
items = sd.extract_all(".athing", fields, content)
6563

6664
# The result is a list of dictionaries, each containing the title and URL of a news item.
6765
# Here, we assert that 30 items are extracted, which is the typical number of news items on the Hacker News homepage.
68-
>>> assert len(items) == 30
69-
66+
assert len(items) == 30
7067
```
7168

7269

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ ftfy = "^6.1.1"
1414
normality = "^2.5.0"
1515

1616
[tool.poetry.group.dev.dependencies]
17-
pytest = "^6.1"
17+
pytest = "^7.1"
18+
pytest-markdown-docs = "^0.4.3"
1819

1920
[build-system]
2021
requires = ["poetry-core>=1.0.0"]

tox.ini

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ deps =
2525
commands = pytest
2626

2727
[testenv:doctest]
28-
commands = python -m doctest README.md
28+
deps =
29+
pytest
30+
pytest-markdown-docs
31+
32+
commands = pytest --markdown-docs
2933

3034
[testenv:format]
3135
deps =

0 commit comments

Comments
 (0)