from fastapi import FastAPI
import sqlite3, os, hashlib
from flask import Flask, jsonify, render_template, request

class AccidentalVuln():
   def fastapi():
        app = FastAPI()
        @app.get("/")
        async def index():
            return {"message": "Intentionally vulnerability added"}

def function1():
    value = 10
    try:
        print(value)
        return {"msg": value}
    except Exception:
        # Below Line (11). Code has Low Severity Issue..
        pass
        #Below Line (13). Fix of Low Issue
       # return {"msg": "Error Occured,please retry"}

@app.route('/api/v1.0/storeAPI/<item>', methods=['GET'])
def searchAPI(item):
    g.db = connect_db()

    #Below Line(20). Code has Medium Severity Issue....
    curs = g.db.execute("SELECT * FROM shop_items WHERE name = '%s'" %item)
    #curs = g.db.execute("SELECT * FROM shop_items WHERE name=?", item) #The safe way to actually get data from db.

    results = [dict(name=row[0], quantity=row[1], price=row[2]) for row in curs.fetchall()]
    g.db.close()
    print("some log")
    return jsonify(results)

# Create password hashes
def hash_pass(passw):
    # Below Line(28). Code has High Severity Issue
    m = hashlib.md5()
    # Below Line(30). Fix of High Severity Issue
    #m = hashlib.sha256() #using SHA-256
    m.update(passw.encode('utf-8'))
    return m.hexdigest()
