コード例 #1
0
def run_cam():
    """Init Pi camera module and takes photos

    :return: Nothing
    """

    camera = picamera.PiCamera()

    # Initial photos settings
    sleep_time = int(
        helpers.get_setting(CONFIG_FILE_NAME, 'Photos', 'sleep_time'))
    frame_count = int(
        helpers.get_setting(CONFIG_FILE_NAME, 'Photos', 'frame_count'))

    # TODO Replace this printings with logging
    print('Photography process will take approximately ',
          str(int(frame_count) * int(sleep_time) / 60), ' minutes')
    print('Taking photos now...')

    try:
        for frame in range(frame_count):
            print('Picture: ' + str(frame) + ' of ' + str(frame_count))
            camera.capture('image' + str(frame).zfill(4) + '.jpg')
            time.sleep(sleep_time)
    except Exception as e:
        # TODO Replace this printings with logging
        print('Can`t take photos, error {} occured '.format(e))
    else:
        # TODO Replace this printings with logging
        print('No errors occured during the photographing process.')
    finally:
        camera.close()
コード例 #2
0
def create_timelapse_movie():
    """Creates time-lapse movie and moves it to specific directory

    :return:
    """
    # Initial movie settings
    movie_dir = helpers.get_setting(CONFIG_FILE_NAME, 'Environment',
                                    'movie_dir')

    # TODO Replace this printings with logging
    print('-------Converting photos to movie now-------')
    os.system(
        'ffmpeg -r 24 -i image%04d.jpg -vcodec libx264 -crf 20 -g 15 `date +%Y%m%d%H%M`timelapse.mp4'
    )
    print('----------------Movie ready-----------------')

    # TODO Replace this printings with logging
    # Checking if dir exists or creating directory
    if not os.path.exists(movie_dir):
        print('Can`t find dir for movie, creating...')
        try:
            os.mkdir(movie_dir)
        except Exception as e:
            print('Can`t create dir for movie, error {} occured '.format(e))

    print('Moving completed mp4 file')
    os.system('mv *.mp4 {}'.format(movie_dir))

    print('Cleaning up old jpgs')
    os.system('rm *.jpg')

    print('Done')
コード例 #3
0
ファイル: models.py プロジェクト: davidrenne/django-history
    def add(self, action, changes, model, user=None, object_id=None):
        if not getattr(settings, "DJANGO_HISTORY_TRACK", True):
            return
        request = get_current_request()
        if not user:
            if request:
                user = request.user
        user_id = user.pk if user else None
        model_ct = ContentType.objects.get_for_model(model)
        model_id = model_ct.pk
        object_id = object_id or model.pk

        # exclusion / none -checks
        excludes = get_setting("EXCLUDE_CHANGES")
        if excludes:
            excludes_for_model = excludes.get("{0}.{1}".format(model_ct.app_label, model_ct.model))
            if excludes_for_model:
                for k, v in copy.deepcopy(changes).iteritems():
                    if k in excludes_for_model.get("fields", []):
                        del changes[k]
        if not changes:
            return

        # for FKs, get old/new information
        fields = model._meta.local_fields

        def get_item(model, pk):
            value = None
            if isinstance(pk, models.Model):
                pk = copy.deepcopy(pk.pk)
            try:
                value = unicode(model.objects.get(pk=pk))
            except Exception, e:
                if settings.DEBUG:
                    print e
            return value
コード例 #4
0
from django.conf import settings
from django.middleware.csrf import get_token

from helpers import get_setting

_thread_locals = None
if get_setting('GET_CURRENT_REQUEST'):
    import importlib
    request_module, request_function = get_setting('GET_CURRENT_REQUEST')
    get_current_request = getattr(importlib.import_module(request_module), request_function)
else:
    import threading
    _thread_locals = threading.local()
    def get_current_request():
        return getattr(_thread_locals, 'request', None)

def reset_current_request():
    setattr(_thread_locals, 'request', None)

class ThreadLocals(object):

    def process_request(self, request):
        get_token(request) # force CSRFTOKEN setup
        _thread_locals.request = request

    def process_response(self, request, response):
        reset_current_request()
        return response