Ejemplo n.º 1
0
def createBook():
    req_data = request.get_json()
    nomor_buku = req_data.get('nomor_buku')
    judul = req_data.get('judul')
    pengarang = req_data.get('pengarang')
    tahun_terbit = req_data.get('tahun_terbit')
    penerbit = req_data.get('penerbit')
    create_at = datetime.utcnow()
    update_at = datetime.utcnow()

    buku = Buku.query.filter_by(nomor_buku=nomor_buku).first()

    if buku == None:
        book = Buku(nomor_buku=nomor_buku,
                    judul=judul,
                    pengarang=pengarang,
                    tahun_terbit=tahun_terbit,
                    penerbit=penerbit,
                    created_at=create_at,
                    update_at=update_at)

        try:
            db.session.add(book)
            db.session.commit()
            return response.success('', 'Berhasil Mebambahkan Buku')
        except Exception as e:
            return response.badRequest('', 'Gagal menambahkan Buku !!!')
    else:
        return response.badRequest(
            '', f'Buku dengan nomor #{nomor_buku} sudah ada')
def login():
    try:
        email = request.json['email']
        password = request.json['password']

        user = Users.query.filter_by(email=email).first()
        if not user:
            return response.badRequest([], 'Empty....')

        if not user.checkPassword(password):
            return response.badRequest([], 'Your credentials is invalid')

        data = singleTransform(user, withBooking=False)
        expires = datetime.timedelta(days=1)
        expires_refresh = datetime.timedelta(days=3)
        access_token = create_access_token(data,
                                           fresh=True,
                                           expires_delta=expires)
        refresh_token = create_refresh_token(data,
                                             expires_delta=expires_refresh)

        return response.ok(
            {
                "data": data,
                "token_access": access_token,
                "token_refresh": refresh_token,
            }, "")

    except Exception as e:
        print(e)
Ejemplo n.º 3
0
def login():
    try:
        email = request.form.get('email')
        password = request.form.get('password')

        user = User.query.filter_by(email=email).first()

        if not user:
            return response.badRequest([], 'Email Tidak Terdaftar')

        if not user.checkPassword(password):
            return response.badRequest([], 'Kombinasi Password Salah !')

        data = singleObject(user)
        expires = datetime.timedelta(days=1)
        expires_refresh = datetime.timedelta(days=3)
        access_token = create_access_token(data,
                                           fresh=True,
                                           expires_delta=expires)
        refresh_token = create_refresh_token(data,
                                             expires_delta=expires_refresh)

        return response.success(
            {
                "data": data,
                "access_token": access_token,
                "refresh_token": refresh_token,
            }, "Success")

    except Exception as e:
        print(e)
Ejemplo n.º 4
0
def show(userId):
    try:
        users = Users.query.filter_by(id=userId).first()
        if not users:
            return response.badRequest([], "User not found")

        data = singleTransform(users)
        return response.ok(data, "Users Detail")
    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 5
0
def tampilMahasiswa():
    try:
        mhs = Mahasiswa.query.all()
        if data is None:
            return response.badRequest("", "Tidak ada data mahasiswa")

        data = [serializeMahasiswa(data) for data in mhs]
        return response.success(data, "Success")
    except Exception as e:
        return response.badRequest("", "Tidak dapat menampilkan")
Ejemplo n.º 6
0
def show(tweetId):
    try:
        tweets = Tweets.query.filter_by(id=tweetId).first()
        if not tweets:
            return response.badRequest([], "Data not found")

        data = singleTransform(tweets)
        return response.ok(data, "Detail")
    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 7
0
    def get(self, id):
        try:
            users = Users.query.filter_by(id=id).first()
            if not users:
                return response.badRequest([], 'Empty....')

            data = singleTransform(users)
            return response.ok(data, "")
        except Exception as e:
            return response.badRequest('', e)
Ejemplo n.º 8
0
def delete(detectionId):
    try:
        detection = Detection.query.filter_by(id=detectionId).first()
        if not detection:
            return response.badRequest([], "Data not found")

        db.session.delete(detection)
        db.session.commit()

        return response.ok("", "Successfully delete data!")
    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 9
0
def delete(userId):
    try:
        user = Users.query.filter_by(id=userId).first()
        if not user:
            return response.badRequest([], "User not found")

        db.session.delete(user)
        db.session.commit()

        return response.ok("", "Successfully delete data!")
    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 10
0
def deleteMahasiswa(npm):
    mhs = Mahasiswa.query.filter_by(npm=npm).first()

    if mhs is None:
        return response.badRequest('', f'Mahasiswa dengan NPM #{npm} tidak ada')

    try:
        db.session.delete(mhs)
        db.session.commit()
        return response.success('', 'Success')
    except Exception as e:
        return response.badRequest('', 'Gagal Menambahkan')
Ejemplo n.º 11
0
def detailMahasiswabynpm(npm):
    try:
        dataMhs = db.session.query(Mahasiswa.npm, Mahasiswa.nama, Mahasiswa.no_hp, Mahasiswa.angkatan, Mahasiswa.alamat, Prodi.nama_prodi, Fakultas.nama_fakultas).select_from(Mahasiswa).join(
            Prodi).join(Fakultas).filter(Mahasiswa.npm == npm and Mahasiswa.prodi == Prodi.id_prodi and Prodi.id_fakultas == Fakultas.id_fakultas).first()

        if dataMhs is None:
            return response.badRequest('', 'Data tidak ditemukan')

        data = serializeDetailMahasiswa(dataMhs)
        return response.success(data, 'Success')
    except Exception as e:
        return response.badRequest('', 'Gagal menampilkan')
Ejemplo n.º 12
0
def delete(tweetId):
    try:
        tweet = Tweets.query.filter_by(id=tweetId).first()
        if not tweet:
            return response.badRequest([], "Data not found")

        db.session.delete(tweet)
        db.session.commit()

        return response.ok("", "Successfully delete data!")
    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 13
0
def hapusBook(id):
    book = Buku.query.filter_by(nomor_buku=id).first()

    if book == None:
        return response.badRequest('', f'Buku dengan nomor #{id} tidak ada')
    try:
        db.session.delete(book)
        db.session.commit()
        return response.success('',
                                f'Buku dengan nomor #{id} berhasil di Hapus')
    except Exception as e:
        return response.badRequest('', 'Tidak dapat menghapus')
Ejemplo n.º 14
0
def detect():
    try:
        url = request.json['url']
        s = url.split("/")
        id = s[-1]
        tweet = twitter.get_tweet(id)
        # print(tweet)
        pickle_in = open('model_fakenews.pickle', 'rb')
        pac = pickle.load(pickle_in)
        tfidf = open('tfidf.pickle', 'rb')
        tfidf_vectorizer = pickle.load(tfidf)
        input_data = [tweet.text.rstrip()]
        print(tweet)
        print(tweet.text)
        print(input_data)
        # transforming input
        tfidf_test = tfidf_vectorizer.transform(input_data)
        # predicting the input
        y_pred = pac.predict(tfidf_test)

        result = y_pred[0]

        tes = store(tweet.text, url, result)
        if tes:
            print('sudah disimpan')

        data = customTransform(tweet, result, id)

        return response.ok(data, 'Success')

    except Exception as e:
        print(e)
        return response.badRequest([], 'Failed')
Ejemplo n.º 15
0
def createAnonym():
    try:
        total = Users.query.count() + 1
        numStr = str(total)
        name = "User" + numStr.zfill(3)
        email = "anonymous" + numStr.zfill(3) + "@mail.com"
        password = "******"
        gender = "Male"
        avatar = getAvatar(gender)
        bio = "Some meaningless made up words"
        role = "client"

        user = Users(name=name,
                     email=email,
                     gender=gender,
                     avatar=avatar,
                     bio=bio,
                     role=role)
        user.setPassword(password)
        db.session.add(user)
        db.session.commit()

        data = {
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "gender": user.gender,
            "avatar": user.avatar,
        }
        return response.ok(data, "Successfully create data!")

    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 16
0
def login():
    try:

        if current_user.is_authenticated:
            return response.ok(current_user.name, "Already Logged in!")

        email = request.json["email"]
        password = request.json["password"]
        remember_me = request.json["remember_me"]

        user = Users.query.filter_by(email=email).first()
        if user is None or not user.checkPassword(password):
            return response.customRequest([], "Invalid email or password", 401)

        login_user(user, remember=remember_me)
        data = {
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "gender": user.gender,
            "avatar": user.avatar,
            "bio": user.bio,
            "role": user.role,
            "created_at": user.created_at,
        }
        return response.ok(data, "Successfully logged in!")

    except Exception as ex:
        return response.badRequest([], str(ex))
Ejemplo n.º 17
0
def index():
    try:
        users = Users.query.all()
        data = transform(users)
        return response.ok(data, "User Lists")
    except Exception as e:
        return response.badRequest([], str(e))
    async def store(request: Request) -> JSONResponse:
        try:
            body = await request.json()
            title = body['title']
            user_id = body['user_id']

            todo = Todos()
            todo.title = title
            todo.owner = user_id
            todo.save()

            todos = TodoTransformer.singleTransform(todo)

            # Menyiapkan payload yang akan dikirim ke worker
            payload = {
                "todo_title": title,
                "user_id": user_id,
                "todo_id": str(todo.id)
            }

            # Menjalankan paylaod
            CreateTodoLog.execute.delay(payload)

            return response.ok(todos, "Berhasil Membuat Todo!")
        except Exception as e:
            return response.badRequest('', f'{e}')
 async def index(request: Request) -> JSONResponse:
     try:
         todos = Todos.objects.all()
         todos = TodoTransformer.transform(todos)
         return response.ok(todos, '')
     except Exception as e:
         return response.badRequest('', f'{e}')
Ejemplo n.º 20
0
def login():
    try:
        email = request.json['email']
        password = request.json['password']

        user = User.query.filter_by(email=email).first()
        if not user:
            return response.badRequest([], 'Email yang dimasukkan salah !')

        if not user.checkPassword(password):
            return response.badRequest([], 'Password salah !')

        data = singleTransform(user)
        return response.ok(data, "Berhasil Login")
    except Exception as e:
        print(e)
Ejemplo n.º 21
0
 async def index(request: Request) -> JSONResponse:
     try:
         users = Users.objects()
         transformer = UserTransformer.transform(users)
         return response.ok(transformer, "")
     except Exception as e:
         return response.badRequest('', f'{e}')
Ejemplo n.º 22
0
def update(userId):
    try:
        name = request.json["name"]
        email = request.json["email"]
        password = request.json["password"]
        gender = request.json["gender"]
        bio = request.json["bio"]

        user = Users.query.filter_by(id=userId).first()

        if name.strip():
            user.name = name

        if email.strip():
            user.email = email

        if password.strip():
            user.setPassword(password)

        if gender.strip() != user.gender:
            user.gender = gender
            user.avatar = getAvatar(gender)

        if bio.strip():
            user.bio = bio

        user.setUpdated()
        db.session.commit()

        return response.ok("", "Successfully update data!")

    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 23
0
def update(detectionId):
    try:
        user_id = request.json["user_id"]
        account = request.json["account"]
        result = request.json["result"]
        start = request.json["start"]
        end = request.json["end"]

        detection = Detection.query.filter_by(id=detectionId).first()

        if user_id.strip():
            detection.user_id = user_id

        if account.strip():
            detection.account = account

        if result.strip():
            detection.result = result

        if start.strip():
            detection.start = start

        if end.strip():
            detection.end = end

        detection.setUpdated()
        db.session.commit()

        return response.ok("", "Successfully update data!")

    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 24
0
    def post(self):
        try:
            identifier = request.json['phone']
            req_source = request.json['app_id']

            # user = None #Users.query.filter_by(identifier=identifier).first()
            # if not user:
            user = Users()
            user.identifier = identifier
            user.req_source = req_source

            # return response.badRequest([], 'Empty....')

            # if not user.checkPassword(password):
            #     return response.badRequest([], 'Your credentials is invalid')

            data = singleTransform(user, withTodo=False)
            # print(f"-------------user data is {data}")
            access_token = jwt.encode(data)
            refresh_token = jwt.encode(data, access=False)

            return response.ok(
                {
                    # 'data': data,
                    'access_token': access_token,
                    'refresh_token': refresh_token,
                },
                "")
        except Exception as e:
            return response.badRequest('', e)
Ejemplo n.º 25
0
def dashboard():
    try:
        total_users = Users.query.count()
        total_depressed = (
            Detection.query.filter(Detection.result > 50)
            .group_by(Detection.account)
            .count()
        )
        total_account = Detection.query.group_by(Detection.account).count()

        last = Detection.query.order_by(Detection.id.desc()).first()
        last_detection = singleTransform(last)
        detail = len(last.details.all())
        last_detection["total_tweets"] = detail

        data = {
            "total_account": str(total_account),
            "total_depressed": str(total_depressed),
            "total_users": str(total_users),
            "last_detection": last_detection,
        }

        return response.ok(data, "Dashboard")

    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 26
0
def index():
    try:
        tweets = Tweets.query.all()
        data = transform(tweets)
        return response.ok(data, "Tweet Dataset Lists")

    except Exception as e:
        return response.badRequest([], str(e))
Ejemplo n.º 27
0
def index():
    '''Menampilkan daftar buku yang terdapar pada table buku '''
    try:
        books = Buku.query.all()
        data_buku = fromatArrayBooks(books)
        return response.success(data_buku, 'Success')
    except Exception as e:
        return response.badRequest('', 'Gagal Menampilkan')
Ejemplo n.º 28
0
def show(id):
    try:
        prodi = Prodis.query.filter_by(id=id).first()
        if not prodi:
            return response.badRequest([], 'Empty....')
        data = singleTransform(prodi)
        return response.ok(data, "Data Prodi Ditemukan!")
    except Exception as e:
        print(e)
def show(id):
    try:
        notification = Notifications.query.filter_by(id=id).first()
        if not notification:
            return response.badRequest([], 'Empty....')
        data = singleTransform(notification)
        return response.ok(data, "Data Notification Ditemukan!")
    except Exception as e:
        print(e)
Ejemplo n.º 30
0
def show(id):
    try:
        customer = Customers.query.filter_by(id=id).first()
        if not customer:
            return response.badRequest([], 'Empty....')
        data = singleTransform(customer)
        return response.ok(data,"Data Customer Ditemukan!")
    except Exception as e:
        print(e)