def credits_all(start=None, end=None): if start is None or end is None: credits = Credit.query().fetch() else: splitStart = start.split('-') from_date = datetime.datetime(year=int(splitStart[2]), month=int(splitStart[1]), day=int(splitStart[0])) splitEnd = end.split('-') to_date = datetime.datetime(year=int(splitEnd[2]), month=int(splitEnd[1]), day=int(splitEnd[0])) credits = Credit.query().filter(Credit.date <= to_date, Credit.date >= from_date).fetch() creditsJson = [] for c in credits: creditJson = {} if c.date is not None: creditJson['date'] = str(c.date.strftime('%d/%m/%y - %H:%M')) else: creditJson['date'] = '' creditJson['value'] = str(c.value) creditJson['operator'] = str(c.operator).split('@')[0] creditJson['user'] = str(c.user_email).split('@')[0] creditsJson.append(creditJson) return json.dumps(creditsJson)
def credits_all(start=None, end=None): splitStart = start.split('-') from_date = datetime.datetime(year=int(splitStart[2]), month=int(splitStart[1]), day=int(splitStart[0])) splitEnd = end.split('-') to_date = datetime.datetime(year=int(splitEnd[2]), month=int(splitEnd[1]), day=int(splitEnd[0])) return Credit.query().filter(Credit.date <= to_date, Credit.date >= from_date).fetch()
def credits_yesterday(): yesterday_dt = datetime.datetime.now() - datetime.timedelta(days = 1) from_date = yesterday_dt.replace(hour=0, minute=0, second=0) to_date = yesterday_dt.replace(hour=23, minute=59, second=59) credits = Credit.query().filter(Credit.date <= to_date, Credit.date >= from_date).fetch() credits_str = 'data;valor;operador;usuario \n' total = 0 for c in credits: credit_str = "" if c.date is not None: credit_str += str(c.date.strftime('%d/%m/%y - %H:%M'))+';' else: credit_str += ' ;' credit_str += str(c.value)+';' credit_str += str(c.operator).split('@')[0]+';' credit_str += str(c.user_email).split('@')[0]+' \n' credits_str += credit_str total += c.value make_blob_public(credits_str, 'daily',yesterday_dt.strftime('%d_%m_%y')) mail.send_mail(sender='*****@*****.**', to="[email protected]; [email protected]; [email protected]", subject="[BarzingaNow] - Creditos do dia " + yesterday_dt.strftime('%d_%m_%y'), body="Oi, total de creditos no dia "+yesterday_dt.strftime('%d_%m_%y')+" foi : "+str(total)+".") return "ok"
def add(): user_logged = session['barzinga_user'] user_operator = User.query().filter( User.email == user_logged['email']).get() user_email = request.form['user'] value = float(request.form['value']) user_email = user_email.split('@')[0] + '@dextra-sw.com' userClient = User.query().filter(User.email == user_email).get() if userClient: userClient.credit(value=value) userClient.put() credit = Credit(user_email=user_email, value=value, operator=user_operator.email) credit.put() return 'Barzingas creditados', 204 else: return 'Usuario invalido', 406
def all(): user_logged = session['barzinga_user'] if user_logged: credits = Credit.query().filter( Credit.user_email == user_logged['email']).order( -Credit.date).fetch(10) creditsJson = [] for c in credits: creditJson = {} if c.date is not None: creditJson['date'] = str(c.date.strftime('%d/%m/%y - %H:%M')) else: creditJson['date'] = '' creditJson['value'] = str(c.value) creditJson['operator'] = str(c.operator).split('@')[0] creditJson['user'] = str(c.user_email).split('@')[0] creditsJson.append(creditJson) return json.dumps(creditsJson) else: return 'Usuario invalido', 406