forked from bkircher/intro-python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.py
More file actions
Latest commit
40 lines (26 loc) · 789 Bytes
/
Copy pathecho.py
File metadata and controls
40 lines (26 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
importsys
importrequests
importasyncio
fromrich.consoleimportConsole
fromrich.markdownimportMarkdown
console=Console()
asyncdeffetch_content_async(url):
loop=asyncio.get_event_loop()
response=awaitloop.run_in_executor(None, requests.get, url)
returnresponse
deffetch_content_sync(url):
response=requests.get(url)
returnresponse
asyncdefmain():
iflen(sys.argv) <2:
console.print("Error: URL is missing!")
return
url=sys.argv[-1]
# sync request
response_sync=fetch_content_sync(url)
console.print(Markdown(response_sync.text))
# async
response_async=awaitfetch_content_async(url)
console.print(Markdown(response_async.text))
if__name__=="__main__":
asyncio.run(main())