def get_repos(): if request.method == "GET": base = PostgreSQL.connect() cursor = base.cursor(cursor_factory=psycopg2.extras.RealDictCursor) cursor.execute("SELECT id, author, name, avatar, url, description, language, stars, forks " + " FROM public.repository WHERE test = false") data = jsonify(cursor.fetchall()) cursor.close() base.close() return data, 200 else: return "invalid method " + request.method, 405
def set_repo(): if request.method == "POST": dt = request.get_json() base = PostgreSQL.connect() cursor = base.cursor() query = 'INSERT INTO public.repository(author, name, avatar, url, description, language, stars, forks) ' + \ "VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6}, {7});"\ .format(dt["author"], dt["name"], dt["avatar"], dt["url"], dt["description"], dt["language"], dt["stars"], dt["forks"]) cursor.execute(query) base.commit() cursor.close() base.close() return "{ok: true}", 200 else: return "invalid method " + request.method, 405