def solution(func_map, func_filter, data):
filtered_data = filter(func_filter, data)
mapped_data = map(func_map, filtered_data)
for i, data in enumerate(mapped_data):
if i % 2 == 0:
yield data import math
a = 12345678982734
b = 12351
c = 123
d = 12
def get_first4(n):
power = math.ceil(math.log10(n)) - 4 # Число 4 = нужное количество разрядов слева
if power < 0: # Проверка, что бы не возводить в отрицательную степень
power = 0
return n // 10 ** power
print(get_first4(a), get_first4(b))
print(get_first4(c), get_first4(d)) import api
import config
from api import logger
import time
import random
from api import servers
import utils
from colorama import init
from termcolor import colored
init()
@logger.catch
def start():
main = api.DurakClient(_type="main")
for _ in range(100):
server = random.choice(servers)
logger.info(f"[INFO] Присоеденился к {server[0]+':'+str(server[1])}")
print(colored('EASY: [INFO] Проект был создан Easy Team', 'red'))
main.connect(server)
key2 = main.getSessionKey()
main.verifySession(key2)
main.auth(config.TOKEN)
bot = api.DurakClient(_type="bot")
bot.connect(server)
key = bot.getSessionKey()
bot.verifySession(key)
token = ""
while not token:
try:
token = bot.register()
except:
continue
bot.auth(token)
bot.sendFriendRequest()
_id1 = ""
while not _id1:
_id1 = main.getMessagesUpdate()
main.acceptFriendRequest(_id1)
pwd = bot.createGame()
bot.inviteToGame()
_id = ""
while not _id:
_id = main.getInvites()
main.join(_id, pwd)
bot.ready()
main.ready()
bot.waitingFor()
main.waitingFor()
time.sleep(0.3)
bot.leave(_id)
time.sleep(0.4)
main.leave(_id)
main.deleteFriend(_id1)
bot.sendFriendRequest()
_id2 = ""
while not _id2:
_id2 = main.getMessagesUpdate()
time.sleep(1.5)
main.acceptFriendRequest(_id2)
time.sleep(1.5)
pwd = bot.createGame2()
bot.inviteToGame()
_id3 = ""
while not _id3:
_id3 = main.getInvites()
main.join(_id3, pwd)
bot.ready()
main.ready()
bot.waitingFor()
main.waitingFor()
time.sleep(0.3)
bot.leave(_id3)
time.sleep(0.4)
main.leave(_id3)
main.deleteFriend(_id2)
bot.exit()
time.sleep(1)
start()def change(arr, indexes, value):
head, tail = indexes[:-1], indexes[-1]
for i in head:
arr = arr[i]
arr[tail] = value
>>> arr = [0, 1, 5, [5, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0, 0, 0, 0]]
>>> change(arr, [3, 1, 0], 999)
>>> arr
[0, 1, 5, [5, [999, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0, 0, 0, 0]]import re
import zlib
import base64
with open('epreuve_BAC_2004.pdf', 'rb') as input_file, open('picture.jpg', 'wb') as output_file:
encoded_text = input_file.read()
match = re.search(b'77 0 obj.*?stream(.*?)endstream', encoded_text, re.S)
stream = match.group(1).strip(b'\n')
decompressed = zlib.decompress(stream)
output_file.write(base64.b64decode(decompressed))
def get_session():
session = requests.Session()
session.headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'ru,en-US;q=0.5',
'Accept-Encoding':'gzip, deflate, br',
'DNT':'1',
'Connection':'keep-alive',
'Upgrade-Insecure-Requests':'1',
'Pragma':'no-cache',
'Cache-Control':'no-cache'}
return cfscrape.create_scraper(sess=session)
session = get_session() # Дальше работать как с обычной requests.Sessionimport requests
import cfscrape
def get_session():
session = requests.Session()
session.headers = {
'Host':'www.artstation.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'ru,en-US;q=0.5',
'Accept-Encoding':'gzip, deflate, br',
'DNT':'1',
'Connection':'keep-alive',
'Upgrade-Insecure-Requests':'1',
'Pragma':'no-cache',
'Cache-Control':'no-cache'}
return cfscrape.create_scraper(sess=session)
def artstation():
url = 'https://www.artstation.com/kyuyongeom'
page_url = 'https://www.artstation.com/users/kyuyongeom/projects.json'
post_pattern = 'https://www.artstation.com/projects/{}.json'
session = get_session()
absolute_links = []
response = session.get(page_url, params={'page':1}).json()
pages, modulo = divmod(response['total_count'], 50)
if modulo: pages += 1
for page in range(1, pages+1):
if page != 1:
response = session.get(page_url, params={'page':page}).json()
for post in response['data']:
shortcode = post['permalink'].split('/')[-1]
inner_resp = session.get(post_pattern.format(shortcode)).json()
for img in inner_resp['assets']:
if img['asset_type'] == 'image':
absolute_links.append(img['image_url'])
with open('links.txt', 'w') as file:
file.write('\n'.join(absolute_links))
if __name__ == '__main__':
artstation()