File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,8 +13,25 @@ def init_script():
1313 Run source code found in Hackersandslackers asyncio tutorials.
1414
1515 1. Intro to Async Python: https://hackersandslackers.com/python-concurrency-asyncio/
16- 2. Intro to Async Python : https://hackersandslackers.com/async-requests-with-aiohttp/
16+ 2. Async HTTP Requests with Aiohttp & Aiofiles : https://hackersandslackers.com/async-requests-with-aiohttp/
1717 """
18+ tutorial_part_one ()
19+ time .sleep (3 )
20+ tutorial_part_two ()
21+
22+
23+ def tutorial_part_one ():
24+ """Run `Intro to Async Python` script."""
1825 start_time = time .perf_counter ()
1926 asyncio .run (asyncio_intro_tutorial (start_time ))
27+ LOGGER .warning (
28+ f"Tutorial Part I completed. Starting part II in 3 seconds... \
29+ \n --------------------------------------"
30+ )
31+
32+
33+ def tutorial_part_two ():
34+ """Run `Async HTTP Requests with Aiohttp & Aiofiles` script."""
35+ start_time = time .perf_counter ()
2036 asyncio .run (aiohttp_aiofiles_tutorial (start_time ))
37+ LOGGER .warning (f"Tutorial Part II completed. Thanks for playing!" )
Original file line number Diff line number Diff line change @@ -12,10 +12,16 @@ def formatter(log: dict) -> str:
1212
1313 :returns: str
1414 """
15+ if log ["level" ].name == "INFO" :
16+ return (
17+ "<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
18+ "<fg #cfe2f3>{level}</fg #cfe2f3>: "
19+ "<light-white>{message}</light-white> \n "
20+ )
1521 if log ["level" ].name == "SUCCESS" :
1622 return (
1723 "<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
18- "<light-green >{level}</light-green >: "
24+ "<fg #85de83 >{level}</fg #85de83 >: "
1925 "<light-white>{message}</light-white> \n "
2026 )
2127 if log ["level" ].name == "WARNING" :
Original file line number Diff line number Diff line change 1313from .tasks import create_tasks
1414
1515
16- async def aiohttp_aiofiles_tutorial (start_time ):
16+ async def aiohttp_aiofiles_tutorial (start_time : float ):
1717 """
1818 Open async HTTP session & execute created tasks.
1919
Original file line number Diff line number Diff line change @@ -23,4 +23,4 @@ def loop_completed(result: str):
2323
2424 :param str result: Result of the loop & its execution time.
2525 """
26- LOGGER .success (result )
26+ LOGGER .success (f" { result } \n --------------------------------------" )
Original file line number Diff line number Diff line change @@ -23,6 +23,4 @@ def loop_completed(result: str):
2323
2424 :param str result: Result of the loop & its execution time.
2525 """
26- LOGGER .success (
27- f"{ result } \n --------------------------------------"
28- )
26+ LOGGER .success (f"{ result } \n --------------------------------------" )
You can’t perform that action at this time.
0 commit comments