Beispiel #1
0
 def post(self):
     nusername=self.get_argument('nname')
     npassword=self.get_argument('npassword')
     nclassv=self.get_argument('classv')
     sqli="insert into namepwd (username,pwd,level) values (%s,%s,%s)"
     database.insert(sqli,nusername,npassword,nclassv)
     self.render("static/msg.html",msg="it is ok!")
Beispiel #2
0
    def _save_metadata(self, db_connection):
        sql = ("""
            INSERT INTO metadata
            (fragment_id, `key`, `value`, type_id)
            SELECT %(fragment_id)s, %(key)s, %(value)s, t.type_id
            FROM types AS t
            WHERE
            t.type_name = %(type_name)s
            LIMIT 1
        """)

        for key, data in self.metadata.iteritems():
            params = {
                'fragment_id': self.fragment_id,
                'key': key,
                'value': data['value'],
                'type_name': data['type_name']
            }
            insert(db_connection, sql, params)
Beispiel #3
0
    def _save_fragment(self, db_connection):
        '''
        :param db_connection: an active database connection
        NOTE: this function will update this object's fragment_id, if needed
        :return:
        '''

        # First, go fetch the parent fragment's id, if it exists
        # Yes, I realize that this could probably be combined into a single query with the next one
        sql = ("""
            SELECT f.fragment_id
            FROM fragments AS f
            WHERE
            f.title = %(parent_fragment_title)s AND
            f.wikia_id = %(wikia_id)s
        """)

        params = {
            'parent_fragment_title': self.parent_fragment_title,
            'wikia_id': self.wikia.wikia_id
        }

        row = fetchone(db_connection, sql, params)
        parent_fragment_id = None
        if row is not None:
            parent_fragment_id = row['fragment_id']

        sql = ("""
            INSERT INTO fragments
            (fragment_id, wikia_id, article, title, parent_fragment_id)
            VALUES
            (%(fragment_id)s, %(wikia_id)s, %(article)s, %(title)s, %(parent_fragment_id)s)
            ON DUPLICATE KEY UPDATE
            wikia_id = VALUES(wikia_id),
            article = VALUES(article),
            title = VALUES(title),
            parent_fragment_id = VALUES(parent_fragment_id)
        """)

        params = {
            'fragment_id': self.fragment_id,
            'wikia_id': self.wikia.wikia_id,
            'article': self.article,
            'title': self.title,
            'parent_fragment_id': parent_fragment_id
        }

        lastrowid = insert(db_connection, sql, params)
        if lastrowid != 0:
            self.fragment_id = str(lastrowid)
Beispiel #4
0
def post_insert_data():
    form_result = {}
    if request.json is None:
        if (request.form.get('EmploymentField')
                not in VALUES['EmploymentField']
                or request.form.get('EmploymentStatus')
                not in VALUES['EmploymentStatus']
                or request.form.get('Gender') not in VALUES['Gender']
                or request.form.get('LanguageAtHome')
                not in VALUES['LanguageAtHome'] or
                request.form.get('JobWherePref') not in VALUES['JobWherePref']
                or request.form.get('SchoolDegree')
                not in VALUES['SchoolDegree']
                or request.form.get('CityPopulation')
                not in VALUES['CityPopulation']
                or request.form.get('MaritalStatus')
                not in VALUES['MaritalStatus']
                or request.form.get('JobPref') not in VALUES['JobPref']
                or request.form.get('HasDebt') not in VALUES['HasDebt']):
            return render_template("insert.html",
                                   selected=VALUES,
                                   message="Value error")
        form_result['EmploymentField'] = request.form.get('EmploymentField')
        form_result['EmploymentStatus'] = request.form.get('EmploymentStatus')
        form_result['Gender'] = request.form.get('Gender')
        form_result['LanguageAtHome'] = request.form.get('LanguageAtHome')
        form_result['JobWherePref'] = request.form.get('JobWherePref')
        form_result['SchoolDegree'] = request.form.get('SchoolDegree')
        form_result['CityPopulation'] = request.form.get('CityPopulation')
        form_result['HasDebt'] = request.form.get('HasDebt')
        form_result['JobPref'] = request.form.get('JobPref')
        form_result['MaritalStatus'] = request.form.get('MaritalStatus')
        try:
            form_result['Income'] = int(request.form.get('Income'))
        except ValueError:
            return render_template("insert.html",
                                   selected=VALUES,
                                   message="Income must be int")
    else:
        form_result = request.json
    with database.create_connection() as conn:
        return render_template("insert.html",
                               selected=VALUES,
                               message=database.insert(conn, form_result))
Beispiel #5
0
    def create_user():
        # Instâcia de retorno
        user = None

        # Leitura do nome do usuário
        username = input("Informe o seu ID do Spotify: ")
        name = input("Informe o seu nome: ")

        # Tenta salvar o registro na base de dados
        user_id = insert("INSERT INTO users (username, name) VALUES (%s, %s)",
                         (username, name))
        if user_id:
            # Informa ao usuário que foi registrado com sucesso
            print("Dados gravados com sucesso!")
            # Cria a instância do usuário e a retorna
            user = (user_id, username, name)
        else:
            # Informa ao usuário que ocorreu um erro
            try_again = input(
                "Ocorreu um erro inesperado. Deseja tentar novamente? (Yes/No)\n"
            )

            # Caso o usuário tenha optado por tentar novamente, chama a função
            if try_again.lower() == "yes" or try_again.lower() == "y":
                return User.create_user()

        # Verifica se o usuário quer atualizar as informações
        check_token = input(
            "Deseja informar o token de acesso ao Spotify agora e já importar seus dados? (Yes/No)\n"
        )

        # Caso o usuário informe sim, que deseja atualizar, consulta os dados e já popula as tabelas
        if check_token.lower() == "yes" or check_token.lower() == "y":
            # Leitura do token
            User.reader_token()

        return user
Beispiel #6
0
#!/usr/bin/python3

from database.database import insert
"""     TODO
    List of tasks 
        - Finish mapping database 
        - Fill all tables 
        - Begin api 
"""

if __name__ == "__main__":
    insert()