def create_program(req): query = query_from_request(req) sql = 'INSERT INTO ru_program \ (title, content, broadcast_id, genre_id, start_date, end_date) \ VALUES \ (%s, %s, %s, %s, %s, %s)' data = ( query.get('title'), query.get('content'), int(query.get('broadcast_id') or 0), int(query.get('genre_id') or 0), parse_date(query.get('start_date')), parse_date(query.get('end_date')), ) print(data) res = DB.execute(sql, param=data, cursor=True) try: newpid = int(res.lastrowid) except: return None print("new program id = {}".format(newpid)) create_episode({ 'program_id': newpid, 'title': 'ALL' }) try: return newpid except: pass return None
def delete_review(id): sql = 'DELETE FROM ru_review WHERE id = %s' try: res = DB.execute(sql, param=(id, )) return res > 0 except: pass return False
def delete_broadcastsystem(id): sql = 'DELETE FROM ru_broadcast_system WHERE id = %s' try: res = DB.execute(sql, param=(id, )) return res > 0 except: pass return False
def create_broadcastsystem(req): query = query_from_request(req) sql = 'INSERT INTO ru_broadcast_system (name) VALUES (%s)' data = ( query.get('name') ) res = DB.execute(sql, param=data, cursor=True) try: return res.lastrowid except: pass return None
def update_review(req, id): query = query_from_request(req) sql = 'UPDATE ru_broadcast_system \ SET name = %s \ WHERE id = %s' data = ( query.get('name') or '', int(id or 0) ) try: res = DB.execute(sql, param=data) return id except: pass return None
def create_person(req): query = query_from_request(req) sql = 'INSERT INTO ru_person (name, job_id, birth_date, details) VALUES (%s, %s, %s, %s)' data = ( query.get('name'), int(query.get('job_id')), parse_date(query.get('birth_date')), query.get('details') ) print(data) res = DB.execute(sql, param=data, cursor=True) try: return res.lastrowid except: pass return None
def create_review(req, author_id): query = query_from_request(req) sql = 'INSERT INTO ru_review (author_id, episode_id, comment, star) VALUES (%s, %s, %s, %s)' data = ( author_id, int(query.get('episode_id')), query.get('comment'), int(query.get('star') or 1) ) print(data) res = DB.execute(sql, param=data, cursor=True) try: return res.lastrowid except: pass return None
def update_person(req, id): query = query_from_request(req) sql = 'UPDATE ru_person \ SET name=%s, job_id=%s, birth_date=%s, details=%s \ WHERE id = %s' data = ( query.get('name'), int(query.get('job_id')), parse_date(query.get('birth_date')), query.get('details') or '', int(id or 0) ) try: res = DB.execute(sql, param=data) return id except: pass return None
def update_episode(req, id): query = query_from_request(req) sql = 'UPDATE ru_episode \ SET program_id=%s, title=%s, content=%s, airdate=%s \ WHERE id = %s' data = ( int(query.get('program_id') or 0), query.get('title'), query.get('content'), parse_date(query.get('airdate')), int(id) ) try: res = DB.execute(sql, param=data) return id except: pass return None
def create_episode(req): query = query_from_request(req) sql = 'INSERT INTO ru_episode \ (program_id, title, content, airdate) \ VALUES \ (%s, %s, %s, %s)' data = ( int(query.get('program_id')), query.get('title'), query.get('content') or '', parse_date(query.get('airdate')) ) res = DB.execute(sql, param=data, cursor=True) try: return res.lastrowid except: pass return None
def update_program(req, id): query = query_from_request(req) sql = 'UPDATE ru_program \ SET title=%s, content=%s, broadcast_id=%s, genre_id=%s, start_date=%s, end_date=%s \ WHERE id = %s' data = ( query.get('title'), query.get('content'), int(query.get('broadcast_id') or 0), int(query.get('genre_id') or 0), parse_date(query.get('start_date')), parse_date(query.get('end_date')), int(id) ) try: res = DB.execute(sql, param=data) return id except: pass return None