Example #1
0
def render_add_movies():
    if request.method == 'GET':
        return render_template('movies/add.html')

    elif request.method == 'POST':
        movies_url = request.form['moviesUrl']
        movies_id = movies_url.split('/')[4]
        movie_data = Movie.get(id=movies_id, ignore=404)
        print('movie data', movie_data)
        if movie_data is None:
            print('id not found, start scraping')
            res_scraping = single_scraping(movies_url)
            new_movie = Movie(title=res_scraping["title"])
            new_movie.rating = res_scraping["rating"]
            new_movie.reviews = res_scraping["review"]
            new_movie.summary = res_scraping["summary"]
            new_movie.writers = res_scraping["writers"]
            new_movie.directors = res_scraping["directors"]
            new_movie.genre = res_scraping["genre"]
            new_movie.stars = res_scraping["stars"]
            new_movie.year = res_scraping["year"]
            new_movie.casts = res_scraping["cast"]
            new_movie.img = res_scraping["img"]
            new_movie.meta.id = movies_id
            new_movie.save()

        es = Elasticsearch()
        res = es.get(index='moovie', doc_type='_doc', id=movies_id)
        return jsonify(res['_source'])
Example #2
0
def post_movie():
    movie = Movie()
    movie.runtime = request.json.get('runtime')
    movie.director = request.json.get('director')
    movie.country = request.json.get('country')
    movie.genre = request.json.get('genre')
    movie.launch_date = request.json.get('launch_date')
    movie.movie_title = request.json.get('movie_title')
    movie.save()
    return movie.to_json(), 200
def scrape_cmd(genre, page_number):
    movies = batch_scraping_by_genre(genre, page_number or 1)

    for res_scraping in movies:
        new_movie = Movie(title=res_scraping["title"])
        new_movie.rating = res_scraping["rating"]
        new_movie.reviews = res_scraping["review"]
        new_movie.summary = res_scraping["summary"]
        new_movie.writers = res_scraping["writers"]
        new_movie.directors = res_scraping["directors"]
        new_movie.genre = res_scraping["genre"]
        new_movie.stars = res_scraping["stars"]
        new_movie.year = res_scraping["year"]
        new_movie.casts = res_scraping["cast"]
        new_movie.img = res_scraping["img"]
        new_movie.meta.id = res_scraping["id"]
        new_movie.save()
        print(new_movie)
Example #4
0
def add_movie(payload):
    try:
        body = request.get_json()
        similar_movie_flag = Movie.query.filter(
            Movie.title == body.get('title')).one_or_none()
        if similar_movie_flag is not None:
            return jsonify({
                'message': 'Similar Movie Title Already Exist in Database.'
            }), 422
        new_movie = Movie(
            title=body.get('title'),
            desc=body.get('desc'),
            release_date=body.get('release_date')
        )
        new_movie.save()
        return jsonify({
            'movie': new_movie.to_json(),
            'success': True
        }), 201

    except Exception:
        abort(500)
Example #5
0
def add():
    form = MovieForm()
    log('进入添加电影路由')
    if form.validate_on_submit():
        data = form.data
        log('输入不为空')
        movie_count = Movie.query.filter_by(title=data['title']).count()
        if movie_count == 1:
            flash("片名已经存在!", "err")
            return redirect(url_for(".add", form=form))
        path = app.config['UP_DIR']
        log('data', data)
        log('form.logo', form.logo)
        log('form.logo.data', form.logo.data)
        log('form.logo.data.filename', form.logo.data.filename)
        url = saved_file(path, form.url.data)
        logo = saved_file(path, form.logo.data)
        movie = Movie(data)
        movie.url = url
        movie.logo = logo
        movie.save()
        flash('添加电影成功!', 'ok')
        return redirect(url_for('.add'))
    return render_template('admin/movie/add.html', form=form)