Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Алёшин Максим #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions check_wiki_cpu_executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time
from urllib.request import Request, urlopen
from urllib.parse import unquote
start = time.time()
with open('res.txt', "r", encoding='utf8') as f:
links = f.readlines()

for url in links:
try:
request = Request(
url,
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 9.0; Win65; x64; rv:97.0) Gecko/20105107 Firefox/92.0'},
)
resp = urlopen(request, timeout=5)
code = resp.code
print(code)
resp.close()
except Exception as e:
print(url, e)

print(f"Время работы: {time.time() - start:.3f} секунд(ы).")
28 changes: 28 additions & 0 deletions check_wiki_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import time
import concurrent.futures
from urllib.request import Request, urlopen
from urllib.parse import unquote
start = time.time()
thread_count = 100
with open('res.txt', "r", encoding='utf8') as f:
links = f.readlines()

def check_url(url):
try:
request = Request(
url,
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 9.0; Win65; x64; rv:97.0) Gecko/20105107 Firefox/92.0'},
)
resp = urlopen(request, timeout=5)
code = resp.code
print(code)
resp.close()
except Exception as e:
print(url, e)

with concurrent.futures.ThreadPoolExecutor(thread_count) as executor:
futures = [executor.submit(check_url, url=url) for url in links]
for future in concurrent.futures.as_completed(futures):
future.result()

print(f"Время работы: {time.time() - start} секунд.")
16 changes: 16 additions & 0 deletions cpu_bound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from hashlib import md5
from random import choice
import time

res_countCoins = 4
currCoins = 0
start_time = time.time()
while currCoins != res_countCoins:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()

if h.endswith("00000"):
print(s, h)
currCoins+=1
res_time = time.time() - start_time
print(f"Время работы: {res_time:.3f} секунд(ы).")
23 changes: 23 additions & 0 deletions cpu_bound_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import time
import random
import concurrent.futures
from hashlib import md5
worker = 100
start_time = time.time()

def generate_coin():
while True:
s = "".join(random.choices("0123456789", k=50))

h = md5(s.encode('utf8')).hexdigest()

if h.endswith("00000"):
return s, h

with concurrent.futures.ThreadPoolExecutor(worker) as executor:
futures = [executor.submit(generate_coin) for i in range(4)]
for future in concurrent.futures.as_completed(futures):
print(*future.result())

res_time = time.time() - start_time
print(f"Время работы: {res_time:.3f} секунд(ы).")
Binary file added cpu_bound_time.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions download_wiki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from urllib.request import urlopen
from urllib.parse import unquote
from bs4 import BeautifulSoup
from tqdm import tqdm
url = 'https://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:%D0%A1%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0'

res = open('res.txt', 'w', encoding='utf8')

for i in tqdm(range(100)):
html = urlopen(url).read().decode('utf8')
soup = BeautifulSoup(html, 'html.parser')
links = soup.find_all('a')

for l in links:
href = l.get('href')
if href and href.startswith('http') and 'wiki' not in href:
print(href, file=res)
897 changes: 897 additions & 0 deletions res.txt

Large diffs are not rendered by default.

Binary file added wiki_process.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wiki_thread.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.