File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
chapter04-dependency-management/src/random_wikipedia_article Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change
1
+ from importlib .metadata import metadata
2
+
1
3
import httpx
2
4
from rich .console import Console
3
5
6
+
4
7
API_URL = "https://en.wikipedia.org/api/rest_v1/page/random/summary"
5
- USER_AGENT = "random-wikipedia-article/0.1 (Contact: you@example.com)"
8
+ USER_AGENT = "{Name}/{Version} (Contact: {Author-email})"
9
+
10
+
11
+ def build_user_agent ():
12
+ fields = metadata ("random-wikipedia-article" )
13
+ return USER_AGENT .format_map (fields )
6
14
7
15
8
16
def main ():
9
- headers = {"User-Agent" : USER_AGENT }
17
+ headers = {"User-Agent" : build_user_agent () }
10
18
11
19
with httpx .Client (headers = headers , http2 = True ) as client :
12
20
response = client .get (API_URL , follow_redirects = True )
You can’t perform that action at this time.
0 commit comments