Skip to content

Instantly share code, notes, and snippets.

View victorusachev's full-sized avatar

Victor Usachev victorusachev

View GitHub Profile
import datetime
import functools
from typing import Callable, Optional
def timed_cache(timedelta: datetime.timedelta,
maxsize: Optional[int] = 128,
typed: Optional[bool] = False) -> Callable:
"""Timeout is applied to the whole cache."""
def decorator(func):
from collections import namedtuple
CreditCondition = namedtuple(
'CreditCondition',
['property_value',
'initial_payment',
'loan_months',
'interest_rate'])
@victorusachev
victorusachev / sqla_example.py
Last active April 2, 2018 03:00
sqla example
from pprint import pprint
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, ForeignKey, Sequence, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, sessionmaker
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
def update_remains_period(actor, start, end, company_object):
"""
Обновить остатки топлива за период.
"""
fuel_infos = FuelInfo.objects.filter(active=True, boiler=company_object)
for date in get_period_dates(start, end):
for fuel_info in fuel_infos:
# Запись, которую нужно обновить
record = None
try:
#!/usr/bin/env python
# –*– encoding: UTF-8 –*–
'''ftp_updown.py: connection to FTP and up & down function'''
__author__ = 'frantisekrehor.cz'
__email__ = 'hi@frantisekrehor.cz'
#================================================================
# The contents of this file are subject to the Common Public Attribution
# License Version 1.0. (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
# License Version 1.1, but Sections 14 and 15 have been added to cover use of
# software over a computer network and provide for limited attribution for the
# Original Developer. In addition, Exhibit A has been modified to be consistent
# with Exhibit B.
#
# Software distributed under the License is distributed on an "AS IS" basis,
from fabric.api import local
import pip
def freeze ():
local("pip freeze > requirements.txt")
local("git add requirements.txt")
local("git commit -v")
def upgrade ():
for dist in pip.get_installed_distributions():