A versão original(em inglês) pode ser encontrada aqui
Um guia com as "melhores das melhores práticas" (BOBP) para o desenvolvimento em Python.
| [uwsgi] | |
| processes = 2 | |
| http-socket = localhost:8001 | |
| uid = 165 | |
| gid = 165 | |
| module = graphite_api.app:app | |
| daemonize2 = /var/log/uwsgi-graphiteapi.log | |
| env = GRAPHITE_API_CONFIG=/usr/local/etc/graphite-api.yaml |
| from django.db import connection | |
| def idseq(model_class): | |
| return '{}_id_seq'.format(model_class._meta.db_table) | |
| def get_next_id(model_class): | |
| cursor = connection.cursor() | |
| sequence = idseq(model_class) | |
| cursor.execute("select nextval('%s')" % sequence) | |
| row = cursor.fetchone() |
A versão original(em inglês) pode ser encontrada aqui
Um guia com as "melhores das melhores práticas" (BOBP) para o desenvolvimento em Python.
| import boto3 | |
| import datetime | |
| import json | |
| from requests_aws4auth import AWS4Auth | |
| import requests | |
| boto3.setup_default_session(region_name='us-east-1') | |
| identity = boto3.client('cognito-identity', region_name='us-east-1') | |
| account_id='XXXXXXXXXXXXXXX' |
| """ | |
| Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for | |
| some reason. | |
| This exception is not managed by Django Rest Framework because it occurs after its validation | |
| process. So at the end, you'll have a 500. | |
| Correcting this is as simple as overriding the exception handler, by converting the Django | |
| ``ValidationError`` to a DRF one. | |
| """ | |
| from django.core.exceptions import ValidationError as DjangoValidationError |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import requests,sys,re | |
| dados = {'nome':'','renach':'','cpf':'','dataNascimento':'','local':'','cfc':'','resultado':'', 'data':'','hora':''} | |
| def get_dados(contents): # Regex tags XML | |
| nome = re.search('<nome>(.*)</nome>',contents).group(0).replace('<nome>','').replace('</nome>','') | |
| renach = re.search('<renach>(.*)</renach>',contents).group(0).replace('<renach>','').replace('</renach>','') |
| #-*- coding: utf-8 -*- | |
| """RoundRobin is a Python library that allow to use Redis for a message queue""" | |
| from functools import wraps | |
| import multiprocessing | |
| from redis import Redis | |
| try: | |
| import cPickle as pickle |
| def enable_timeit(number=1000, repeat=1): | |
| """ | |
| Adds a `timeit` member function to the decorated function. | |
| This function allows for configuration of how `timeit` will be executed for | |
| the decorated function. Note that ultimately, `timeit.repeat()` will be | |
| called, not `timeit.timeit()`. | |
| Args: | |
| number (int): How often `timeit` should execute the function. |
| """ | |
| Logical deletion for Django models. Uses is_void flag | |
| to hide discarded items from queries. Overrides delete | |
| methods to set flag and soft-delete instead of removing | |
| rows from the database. | |
| """ | |
| from django.apps import apps | |
| from django.contrib.admin.utils import NestedObjects | |
| from django.db import models | |
| from django.db.models import signals |