This file contains hidden or 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
| """ | |
| dependencies: | |
| flask = "^1.1.1" | |
| flask_marshmallow = "^0.10.1" | |
| flask_sqlalchemy = "^2.4.1" | |
| marshmallow-sqlalchemy = "^0.21.0" | |
| """ | |
| import sys |
This file contains hidden or 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
| import lxml.etree as ET | |
| import csv | |
| # load file | |
| tree = ET.parse('users.xml') | |
| # iterate through each user tag | |
| users = tree.findall('.//user') | |
| all_roles = list({role.find('name').text for role in tree.findall('.//role')}) | |
| # just w mode, no wb. wb for binary data | |
| with open('user_list.csv', "w") as csv_file: |
This file contains hidden or 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
| from aiohttp import web, ClientSession | |
| from aiohttp.web import middleware | |
| async def search(request): | |
| q = request.query.get("q", "") | |
| session = request.app["client_session"] | |
| async with session.get("https://ya.ru", params={"q": q}) as request: | |
| body = await request.read() | |
| return web.Response(body=body, headers={"content-type": "text/html"}) |
This file contains hidden or 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
| import logging | |
| import requests | |
| # init simpliest custom logger | |
| logger = logging.getLogger("myAwesomeLogger") | |
| logger.setLevel(logging.DEBUG) | |
| logger.addHandler(logging.StreamHandler()) |
This file contains hidden or 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
| import pprint | |
| from collections import namedtuple | |
| # fields names mapping | |
| fields = { | |
| "Название": "name", | |
| "Сорт": "sort", | |
| "Цена": "price", | |
| "Картинка": "image", | |
| } |
This file contains hidden or 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
| # GDAL | |
| sudo apt install gdal-bin libgdal-dev | |
| pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal" | |
| # MAPNIK | |
| sudo apt install mapnik-utils libmapnik-dev libboost-all-dev | |
| mapnik-config -v # check mapnik version | |
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| from __future__ import unicode_literals | |
| from __future__ import print_function | |
| from __future__ import absolute_import | |
| import base64 | |
| import pytest | |
| import pytest_twisted |
This file contains hidden or 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
| from typing import Dict, Any, List | |
| import abc | |
| class Repository(abc.ABC): | |
| def __init__(self, model): | |
| self.model = model # or connection pool | |
| def create_one(self, data: Dict[str, Any]): | |
| item = self.model.from_dict(data) |
This file contains hidden or 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
| import math | |
| import signal | |
| from concurrent.futures import ProcessPoolExecutor | |
| from contextlib import suppress | |
| from time import sleep | |
| values = [40000000, 30000000, 20000000, 10000000] | |
| PRIMES = [ | |
| 112272535095293, |
This file contains hidden or 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
| from typing import ( | |
| Generic, Optional, TYPE_CHECKING, | |
| Type, TypeVar, Union, overload, | |
| ) | |
| T = TypeVar("T", bound="A") # noqa | |
| class Descr(Generic[T]): | |
| @overload |
OlderNewer