-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 44e7b77
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import math | ||
|
||
|
||
def is_prime(number: int) -> bool: | ||
for divider in range(2, math.ceil(number / 2) + 1): | ||
if number % divider == 0: | ||
return False | ||
return True | ||
|
||
|
||
def get_prime_numbers(max_number: int) -> list[int]: | ||
result = list() | ||
if max_number < 2: | ||
return result | ||
for i in range(2, max_number + 1): | ||
if is_prime(i): | ||
result.append(i) | ||
return result | ||
|
||
|
||
print(get_prime_numbers(5300)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
aiohttp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import asyncio | ||
import os | ||
import time | ||
import aiohttp | ||
|
||
|
||
def write_file(data): | ||
with open(f'images/{time.time_ns()}.jpeg', 'wb') as f: | ||
f.write(data) | ||
|
||
|
||
async def get_page_content(url: str, session): | ||
async with session.get(url, allow_redirects=True) as response: | ||
data = await response.read() | ||
write_file(data) | ||
|
||
|
||
async def get_web_pages_data(urls: list[str]): | ||
tasks = list() | ||
async with aiohttp.ClientSession() as session: | ||
for i, url in enumerate(urls): | ||
task = asyncio.ensure_future( | ||
get_page_content(url, session) | ||
) | ||
tasks.append(task) | ||
if i % 20 == 0: | ||
await asyncio.gather(*tasks) | ||
tasks = list() | ||
await asyncio.gather(*tasks) | ||
|
||
|
||
if __name__ == '__main__': | ||
if not os.path.exists('images'): | ||
os.mkdir('images') | ||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) | ||
urls = ['https://loremflickr.com/320/240'] * 100 | ||
asyncio.run(get_web_pages_data(urls)) |