예제 #1
0
def get_data_id():
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute("""SELECT MAX(data_id) AS id FROM blogdata""")
    for row in rows:
        id = row.id
    return id
예제 #2
0
def create_user(username, password, display_name):
    hash_password = encode_password(password)
    session = get_session()
    session.set_keyspace(keyspace)
    session.execute(
        """INSERT INTO users (username, password, display_name) VALUES (%s, %s, %s)""",
        (username, hash_password, display_name))
예제 #3
0
def get_article_by_id(id):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute("""SELECT * FROM blogdata where data_id = %s AND datatype = %s ALLOW FILTERING""", (int(id), 'A'))
    if rows:
        return rows
    return False
예제 #4
0
def get_article_details(username, id):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute("""SELECT * FROM blogdata where username = %s AND data_id = %s ALLOW FILTERING""",
        (username, int(id)))
    if rows:
        return True
    return False
예제 #5
0
def count_comments(id):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute(
        """SELECT COUNT(*) from blogdata WHERE data_id = %s and datatype = %s""",
        (int(id), 'C'))
    n_comments = rows[0]
    return n_comments
예제 #6
0
def edit_article(title, text, id):
    session = get_session()
    session.set_keyspace(keyspace)
    unix = int(time.time())
    data_type = "A"
    last_updated_time = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    session.execute("""UPDATE blogdata SET title = %s, text = %s, last_updated_time = %s WHERE data_id = %s AND datatype = %s""",
                  (title, text, last_updated_time, int(id), data_type))
예제 #7
0
def get_user_details(username):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute("""SELECT * FROM users WHERE username = %s""",
                           (username, ))
    if rows:
        return rows
    return False
예제 #8
0
def get_comment(id):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute(
        """SELECT data_id as id FROM blogdata WHERE data_id = %s AND datatype = %s""",
        (int(id), 'C'))
    for row in rows:
        id = row.id
    return id
예제 #9
0
def get_comments(id, no_of_comments):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute(
        """SELECT * from blogdata where data_id = %s AND datatype = %s LIMIT %s""",
        (int(id), 'C', int(no_of_comments)))
    if rows:
        return rows
    return False
예제 #10
0
def get_article_id(id):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute(
        """SELECT * FROM blogdata where data_id = %s and datatype = %s""",
        (int(id), 'A'))
    if rows:
        return True
    return False
예제 #11
0
def get_n_articles(n):
    session = get_session()
    session.set_keyspace(keyspace)
    data_type = "A"
    rows = session.execute("""SELECT text, username, title, url, post_time, last_updated_time FROM blogdata \
        WHERE datatype = %s ORDER BY data_id DESC LIMIT %s""", (data_type, int(n)))
    if rows:
        return rows
    return False
예제 #12
0
def get_tag_details(url):
    session = get_session()
    session.set_keyspace(keyspace)
    rows = session.execute(
        """SELECT * FROM blogdata WHERE url = %s and datatype = %s ALLOW FILTERING""",
        (url, 'T'))
    if rows:
        return True
    return False
예제 #13
0
def post_article(data_id, username, text, title, url):
    session = get_session()
    session.set_keyspace(keyspace)
    unix = int(time.time())
    data_type = "A"
    post_time = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    last_updated_time = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    session.execute("""INSERT INTO blogdata (data_id, username, text, title, url, datatype, post_time, last_updated_time)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s)""", (data_id, username, text, title, url, data_type, post_time, last_updated_time))
예제 #14
0
def post_tag(data_id, username, tag_name, url):
    session = get_session()
    session.set_keyspace(keyspace)
    data_type = "T"
    unix = int(time.time())
    post_time = str(
        datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    last_updated_time = str(
        datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    session.execute(
        """INSERT INTO blogdata (data_id, datatype, username, url, tag, post_time, last_updated_time) VALUES (%s, %s, %s, %s, %s, %s, %s)""",
        (int(data_id), data_type, username, url, tag_name, post_time,
         last_updated_time))
예제 #15
0
def post_comment(data_id, username, comment):
    session = get_session()
    session.set_keyspace(keyspace)
    unix = int(time.time())
    datatype = 'C'
    post_time = str(
        datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    last_updated_time = str(
        datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    session.execute(
        """INSERT INTO blogdata (data_id, username, comment, datatype, post_time, last_updated_time) VALUES (%s, %s, %s, %s, %s, %s)""",
        (int(data_id), username, comment, datatype, post_time,
         last_updated_time))
예제 #16
0
def delete_user(username):
    session = get_session()
    session.set_keyspace(keyspace)
    session.execute("""DELETE FROM users WHERE username = %s""", (username, ))
예제 #17
0
def delete_article(id):
    session = get_session()
    session.set_keyspace(keyspace)
    data_type = "A"
    session.execute("""DELETE FROM blogdata WHERE data_id = %s AND datatype = %s""", (int(id), data_type))
예제 #18
0
def delete_comment(id, username):
    session = get_session()
    session.set_keyspace(keyspace)
    session.execute(
        """DELETE FROM blogdata WHERE data_id = %s AND datatype = %s""",
        (int(id), 'C'))
예제 #19
0
def update_password(username, new_password):
    hash_password = encode_password(new_password)
    session = get_session()
    session.set_keyspace(keyspace)
    session.execute("""UPDATE users SET password = %s WHERE username = %s""",
                    (hash_password, username))
예제 #20
0
def delete_tag(url):
    session = get_session()
    session.set_keyspace(keyspace)
    session.execute(
        """DELETE FROM blogdata WHERE url = %s AND datatype = %s ALLOW FILTERING""",
        (url, 'T'))