def timed_lru_cache(seconds: int, maxsize: int = 128) -> Callable:
def wrapper_cache(func):
func = lru_cache(maxsize=maxsize)(func)
func.lifetime = timedelta(seconds=seconds)
func.expiration = datetime.utcnow() + func.lifetime
@wraps(func)
def wrapped_func(*args, **kwargs):
if datetime.utcnow() >= func.expiration:
func.cache_clear()
func.expiration = datetime.utcnow() + func.lifetime
return func(*args, **kwargs)
return wrapped_func
return wrapper_cache
def combine(original_list, maxlen=20):
outer_list = []
accum = []
for sublist in original_list:
# if the next set of values will fit, extend the sublist
if len(accum) + len(sublist) <= maxlen:
accum.extend(sublist)
else:
# otherwise start a new sublist
outer_list.append(accum)
accum = list(sublist)
# pick up any values that are left over
if accum:
outer_list.append(accum)
return outer_list
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"--path",
dest="path",
default=os.path.join(os.path.abspath(os.path.dirname(__name__)), 'data.csv')
)
def handle(self, *args, **options):
path = options.get("path")
...
call_command('my_command', path=create_test_csv_file)
task_list = [task1(), task2()]
res = await asyncio.gather(*task_list, return_exceptions=True) # res = ["result", ArithmeticError()]
res = list(map(lambda r: r if not isinstance(r, Exception) else default_value, res)) # res = ["result", None]
_, to_rar = (os.path.split(to_rar))
new_file_name = self.generate_file_name() # Генерация имени файла
path_to_temp_folder = os.path.dirname(BASE_DIR)
if not os.path.exists(f'{path_to_temp_folder}/files'):
pathlib.Path(f'{path_to_temp_folder}/files').mkdir(parents=True, exist_ok=True) # Создаю папку
wb.save(f'{path_to_temp_folder}/files/{new_file_name}') # Сохраняю в нее эксель файл
archive = self.generate_zip_name(rfi) # функция генерит имя архива (string)
to_rar = f'{path_to_temp_folder}/files' # путь к папке с файлами
_, to_rar = (os.path.split(to_rar)) # Новая строка
os.system("rar a {} {}".format(archive, to_rar)) # Вызов линуксовой либы для создания архива
folder.rar
folder
file.xlsx
"link": HOST + item.find("a", class_="js-item-slider").get('href'),
version: '3.7'
services:
web:
build: .
command: python /profi/manage.py runserver 0.0.0.0:8000
environment:
# DJANGO_SETTINGS_MODULE: "project.settings.development"
DEBUG: 1
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST: db
volumes:
- .:/profi
ports:
- "${HTTP_PORT:-8000}:8000"
depends_on:
- db
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/posgresql/data/
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST: db
ports:
- "${DB_PORT:-5432}:5432"
volumes:
postgres_data:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('POSTGRES_DB', default='postgres'),
'USER': os.environ.get('POSTGRES_USER', default='postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', default='postgres'),
'HOST': os.environ.get('POSTGRES_HOST', default='localhost'),
'PORT': "5432"
}
}
<div id="selector">
<select>
<option value="#">Download</option>
<option value="{% url 'cv' format_='docx' %}">DOCX</option>
<option value="{% url 'cv' format_='json' %}">JSON</option>
<option value="{% url 'cv' format_='html' %}">HTML</option>
</select>
</div>
<script>
$(function(){
// bind change event to select
$('#selector select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
eval `ssh-agent`
ssh-add ~/.ssh/<private_key_file>