Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
inuur committed Feb 2, 2023
0 parents commit 44e7b77
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
21 changes: 21 additions & 0 deletions prime_number.py
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))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aiohttp
37 changes: 37 additions & 0 deletions web-scrpaer.py
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))

0 comments on commit 44e7b77

Please sign in to comment.