Skip to content
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
20 changes: 20 additions & 0 deletions iosync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from urllib.request import Request, urlopen
from urllib.parse import unquote
import cProfile
def main():
links = open('res.txt', encoding='utf8').read().split('\n')

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)

cProfile.run('main()')
24 changes: 24 additions & 0 deletions iosync1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import concurrent.futures
import urllib.request
import cProfile

URLS = open('res.txt', encoding='utf8').read().splitlines()


# Retrieve a single page and report the URL and contents
def load_url(url, timeout):
with urllib.request.urlopen(url, timeout=timeout) as conn:
return conn.code

def main():
# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
# Start the load operations and mark each future with its URL
future_to_url = {executor.submit(load_url, url, 5): url for url in URLS}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
code = future.result()
except Exception as exc:
print(url, exc)
cProfile.run('main()')
21 changes: 21 additions & 0 deletions iotest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from urllib.request import urlopen
from urllib.parse import unquote
from bs4 import BeautifulSoup
from tqdm import tqdm
import cProfile

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')
def main():
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)

cProfile.run('main()')
25 changes: 25 additions & 0 deletions monetki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from hashlib import md5
from random import choice
import cProfile
import concurrent.futures


def generate_coins(c):
while True:
s = "".join([choice("0123456789") for i in range(50)])
h = md5(s.encode('utf8')).hexdigest()
if h.endswith("00000"):
c = "{} {}".format(s, h)
break
return c


def main_generate_coins():
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
for coin in zip(executor.map(generate_coins, [0,0,0,0,0,0,0,0])):
print(coin)


if __name__ == '__main__':
main_generate_coins()
cProfile.run('main_generate_coins()')
Loading