def detailpengguna(id): if 'admin' not in session: return redirect(url_for("admin")) partisipan = id c = ControllerPartisipan(None) hasil = c.readsatu(partisipan) disc = hasil[8] penjelasan = hasil[9] kelebihan = hasil[10] kekurangan = hasil[11] hasil_ = json.loads(hasil[6]) maksimal = [0, 0, 0, 0] for x in hasil_: if x["disc"] == "D": maksimal[0] = maksimal[0] + 1 elif x["disc"] == "I": maksimal[1] = maksimal[1] + 1 elif x["disc"] == "S": maksimal[2] = maksimal[2] + 1 elif x["disc"] == "C": maksimal[3] = maksimal[3] + 1 d_ = maksimal[0] i_ = maksimal[1] s_ = maksimal[2] c_ = maksimal[3] payload = [] cursor = mydb.cursor() #subprocess.run(["instagram-scraper",hasil[4],"--media-metadata","--media-types","none","--destination","metadata"]) #if os.path.isfile("metadata/{}.json".format(hasil[4])): # file = open("metadata/{}.json".format(hasil[4]),"r",encoding="utf-8") # x = file.read() # j = json.loads(x) # for x in range(len(j["GraphImages"])): # l = {} # l["id"]=j["GraphImages"][x]["id"] # l["username"]=hasil[4] # l["captionasli"]=j["GraphImages"][x]["edge_media_to_caption"]["edges"][0]["node"]["text"] # l["captionpraproses"]=j["GraphImages"][x]["edge_media_to_caption"]["edges"][0]["node"]["text"] # l["disc"]="Dominance" # print(emoji.demojize(j["GraphImages"][x]["edge_media_to_caption"]["edges"][0]["node"]["text"])) # payload.append(l) #else: # payload=[] return render_template("detailpengguna.html", caption=json.dumps(hasil_), disc=disc, penjelasan=penjelasan, kelebihan=kelebihan, kekurangan=kekurangan, d=d_, i=i_, s=s_, c=c_)
def editpengguna(id): if 'admin' not in session: return redirect(url_for("admin")) if request.method == "POST": try: id = request.form.get("id") nama = request.form.get("name") email = request.form.get("email") jeniskelamin = request.form.get("jeniskelamin") usernameinstagram = request.form.get("usernameinstagram") p = Partisipan(id, nama, email, jeniskelamin, usernameinstagram, None, None) c = ControllerPartisipan(p) c.update() return redirect( url_for("pengguna", show="notifikasi", type="success", msg="Data berhasil diubah!")) except Exception as e: return redirect( url_for("pengguna", show="notifikasi", type="danger", msg=e)) partisipan = id cursor = mydb.cursor() query = "SELECT * FROM partisipan WHERE id_partisipan = %s;" cursor.execute(query, (partisipan, )) hasil = cursor.fetchone() if hasil == None: return redirect(url_for("pengguna")) return render_template("editpengguna.html", data=hasil)
def dashboard(): if 'admin' not in session: return redirect(url_for("admin")) cursor = mydb.cursor() cursor.execute("SELECT count(*) FROM partisipan") a = cursor.fetchone() b = len(os.listdir("metadata")) cursor.execute( "SELECT disc.nama_disc,COUNT(disc.nama_disc) AS jml FROM partisipan INNER JOIN disc ON disc.id_disc=partisipan.id_disc WHERE nama_disc REGEXP '^D' GROUP BY disc.nama_disc" ) d = cursor.fetchone() cursor.execute( "SELECT disc.nama_disc,COUNT(disc.nama_disc) AS jml FROM partisipan INNER JOIN disc ON disc.id_disc=partisipan.id_disc WHERE nama_disc REGEXP '^I' GROUP BY disc.nama_disc" ) i = cursor.fetchone() cursor.execute( "SELECT disc.nama_disc,COUNT(disc.nama_disc) AS jml FROM partisipan INNER JOIN disc ON disc.id_disc=partisipan.id_disc WHERE nama_disc REGEXP '^S' GROUP BY disc.nama_disc" ) s = cursor.fetchone() cursor.execute( "SELECT disc.nama_disc,COUNT(disc.nama_disc) AS jml FROM partisipan INNER JOIN disc ON disc.id_disc=partisipan.id_disc WHERE nama_disc REGEXP '^C' GROUP BY disc.nama_disc" ) c = cursor.fetchone() d = 0 if d == None else d[1] i = 0 if i == None else i[1] s = 0 if s == None else s[1] c = 0 if c == None else c[1] print(d, i, s, c) return render_template("dashboard.html", a=a[0], b=b, d=d, i=i, s=s, c=c)
def admin(): if 'admin' in session: return redirect(url_for("dashboard")) if request.method == 'POST': email = request.form["email"] password = request.form["password"] if len(email) == 0 or len(password) == 0: return render_template("admin.html", type="danger", msg="Masukkan data login!") cursor = mydb.cursor() cursor.execute("SELECT * FROM admin WHERE email=%s", (email, )) adm = cursor.fetchone() if adm: e = adm[1] p = adm[2] if e == email and p == password: session["admin"] = True return redirect(url_for("dashboard")) else: return render_template("admin.html", type="danger", msg="Login gagal!") else: return render_template("admin.html", type="danger", msg="Akun tidak ditemukan!") return render_template("admin.html")
def delete(self,id_partisipan): try: cursor = mydb.cursor() query = 'DELETE FROM partisipan WHERE id_partisipan={}'.format(id_partisipan) cursor.execute(query) mydb.commit() return True except Exception as e: raise ValueError(e)
def update(self): try: cursor = mydb.cursor() query = 'UPDATE partisipan SET nama_lengkap=%s,alamat_email=%s,jenis_kelamin=%s,username_instagram=%s WHERE id_partisipan=%s' cursor.execute(query,(self.partisipan.nama_lengkap,self.partisipan.alamat_email,self.partisipan.jenis_kelamin,self.partisipan.username_instagram,self.partisipan.id_partisipan)) mydb.commit() return True except Exception as e: raise ValueError(e)
def readsatu(self, id): try: cursor = mydb.cursor() query = 'SELECT partisipan.*,disc.* FROM partisipan INNER JOIN disc ON disc.id_disc=partisipan.id_disc WHERE partisipan.id_partisipan=%s' cursor.execute(query,(id,)) hasil = cursor.fetchone() return hasil except: raise ValueError("err")
def read(self): try: cursor = mydb.cursor() query = 'SELECT * FROM partisipan ORDER BY id_partisipan DESC' cursor.execute(query) hasil = cursor.fetchall() return hasil except: raise ValueError("err")
def create(self): try: cursor = mydb.cursor() query = 'INSERT INTO partisipan VALUES (NULL,%s,%s,%s,%s,%s,%s)' cursor.execute(query,(self.partisipan.nama_lengkap,self.partisipan.alamat_email,self.partisipan.jenis_kelamin,self.partisipan.username_instagram,self.partisipan.hasil_pertanyaan,self.partisipan.id_disc)) mydb.commit() return True except Exception as e: raise ValueError(e)
def hasil(): if request.method == "POST": nama = request.form["name"] email = request.form["email"] jenkel = request.form["jeniskelamin"] insta = request.form["usernameinstagram"] payload = [] cursor = mydb.cursor() cursor.execute("SELECT * FROM partisipan WHERE alamat_email=%s", (request.form["email"], )) h = cursor.fetchone() if h == None: subprocess.run([ "instagram-scraper", insta, "--media-metadata", "--media-types", "none", "--destination", "metadata" ]) try: if os.path.isfile("metadata/{}.json".format(insta)): file = open("metadata/{}.json".format(insta), "r", encoding="utf-8") x = file.read() j = json.loads(x) for x in range(len(j["GraphImages"])): l = {} if len(j["GraphImages"][x]["edge_media_to_caption"] ["edges"]) == 0: pass else: l["captionasli"] = j["GraphImages"][x][ "edge_media_to_caption"]["edges"][0]["node"][ "text"] pr = penggal( j["GraphImages"][x]["edge_media_to_caption"] ["edges"][0]["node"]["text"]) print(pr) if len(pr) == 0 or pr == "-": pass else: l["id"] = j["GraphImages"][x]["id"] l["username"] = insta l["captionpraproses"] = penggal( j["GraphImages"][x] ["edge_media_to_caption"]["edges"][0] ["node"]["text"]) l["disc"] = prediksi(model, vectorizer, pr) #print(emoji.demojize(j["GraphImages"][x]["edge_media_to_caption"]["edges"][0]["node"]["text"])) if len(l) == 5: payload.append(l) else: return redirect( url_for("index", type="error", msg="Akun tidak ada atau terkunci!")) except Exception as e: return redirect(url_for("index", type="error", msg=e)) maksimal = [0, 0, 0, 0] for x in payload: if x["disc"] == "D": maksimal[0] = maksimal[0] + 1 elif x["disc"] == "I": maksimal[1] = maksimal[1] + 1 elif x["disc"] == "S": maksimal[2] = maksimal[2] + 1 elif x["disc"] == "C": maksimal[3] = maksimal[3] + 1 maxx = np.argmax(maksimal) + 1 dump = json.dumps(payload) cursor.execute( "INSERT INTO partisipan VALUES (NULL,%s,%s,%s,%s,%s,%s)", (nama, email, jenkel, insta, str(maxx), dump)) mydb.commit() cursor.execute("SELECT * FROM disc WHERE id_disc={}".format(maxx)) prefix = cursor.fetchone() return render_template("hasil.html", nama=nama, email=email, jeniskelamin=jenkel, usernameinstagram=insta, data=dump, penjelasan=prefix[2], kelebihan=prefix[3], kekurangan=prefix[4]) else: return redirect( url_for("index", type="error", msg="Email sudah terdaftar!")) else: return redirect(url_for("index"))