def subscribe(): user_id = current_user.id if not functions.is_subscriber(user_id) and request.form[ 'abb'] != 'null': # controllo che non sia abbonato sub = functions.get_subscription(request.form['abb']) if request.form['abb'] == 'prova': subscriber = classes.Subscriber( id=user_id, abbonamento=sub.id, datainizioabbonamento=functions.get_current_date(), datafineabbonamento=functions.get_increment_date(7), durata=7) session.add(subscriber) else: subscriber = classes.Subscriber( id=user_id, abbonamento=sub.id, datainizioabbonamento=functions.get_current_date(), datafineabbonamento=functions.get_increment_date( int(request.form['durata'])), durata=request.form['durata']) session.add(subscriber) functions.remove_not_subscriber(user_id) session.commit() return redirect(url_for('confirm')) else: return redirect(url_for('wrong'))
async def on_message(message): # Parsing and forwarding the command, if message starts with bot prefix. if message.content.startswith(Config.COMMAND_PREFIX): command = message.content.split()[0][1:] arguments = [] try: arguments = message.content.split()[1:] except IndexError: pass try: await getattr(commands, command)(message, arguments) except Exception as e: logger.error(e) print(e) # Checking user, and adding to database if not exists. user = get_user(discord_id=message.author.id).first() if not user: user = create_user(discord_id=message.author.id) # Properly rewarding user for contribution. if not message.content.startswith(Config.COMMAND_PREFIX): message_length = len(message.content) add_currency_to_user(user.id, Config.CURRENCY_CODE, int(message_length / 5)) # Checking currency conversion data request time. last_update = get_system_variable("currency_last_update") if not last_update: last_update = create_system_variable("currency_last_update", get_current_date()) if (get_current_date() - datetime.strptime(last_update.value, "%Y-%m-%d %H:%M:%S.%f")) >= timedelta(hours=1): update_currencies() last_update.value = get_current_date() session.commit()
def create_user(): new_id = functions.get_id_increment() pw = request.form['password'] + request.form['email'] user = classes.User(id=new_id, username=request.form['username'], password=hashlib.md5(pw.encode()).hexdigest(), nome=request.form['nome'], cognome=request.form['cognome'], email=request.form['email'], datanascita=request.form['dataNascita']) client = classes.Client(id=new_id) session.add(user) session.add(client) if request.form[ 'abb'] != "null": # controllo se è stato scelto oppure no un abbonamento sub = functions.get_subscription(request.form['abb']) if request.form['abb'] == 'prova': subscriber = classes.Subscriber( id=new_id, abbonamento=sub.id, datainizioabbonamento=functions.get_current_date(), datafineabbonamento=functions.get_increment_date(7), durata=7) session.add(subscriber) else: subscriber = classes.Subscriber( id=new_id, abbonamento=sub.id, datainizioabbonamento=functions.get_current_date(), datafineabbonamento=functions.get_increment_date( int(request.form['durata'])), durata=request.form['durata']) session.add(subscriber) else: not_subscriber = classes.NotSubscriber(id=new_id) session.add(not_subscriber) session.commit() return redirect(url_for('confirm'))
def obj_view_redirect(request,obj_type=None): d = functions.get_current_date(request) page = '/benchmarks/' + obj_type + '/' + d.u return HttpResponseRedirect(page)
def summary_redirect(request): d = functions.get_current_date(request) page = '/benchmarks/summary/' + d.u return HttpResponseRedirect(page)