예제 #1
0
def populate_manga():
    print "Populate Manga list"

    this_manga = Manga(nome="Lilith_s_Cord",
                       full_name="Lilith's Cord",
                       link='http://www.mangahere.co/manga/lilith_s_cord/',
                       locandina='lilith_s_cord.jpg')
    db.session.add(this_manga)

    this_manga = Manga(
        nome="Tower_of_God",
        full_name="Tower of God",
        link='http://pignaquegna.altervista.org/series/tower_of_god/',
        locandina='tower_of_god.jpg')
    db.session.add(this_manga)

    this_manga = Manga(nome="The_Gamer",
                       full_name="the Gamer",
                       link='http://www.mangaeden.com/it/it-manga/the-gamer/',
                       locandina='the_gamer.png')
    db.session.add(this_manga)

    db.session.commit()

    print Manga.query.all()
예제 #2
0
def add_manga():
    name = request.form["manga_name"]
    url = request.form["manga_url"]
    file = request.files["manga_cover"]

    # Handle the case where there are conflicting manga names
    if Manga.query.filter_by(name=name).first():
        error_text = "Manga title already exists."
        return render_template('admin.html', error=error_text)

    # Handle the case where there are conflicting manga urls
    if os.path.exists(application.config['UPLOAD_FOLDER'] + url):
        return render_template('admin.html', error="Manga URL already exists.")

    # Handle the case where the file is not sent
    if not (file and allowed_file(file.filename)):
        return render_template('admin.html', error="Invalid Cover File.")

    # Save the file to the server
    cover_filename = rename(file, "cover")
    cover_url = save_file(file, url, cover_filename)

    # Then, just dump the contents into the database
    author = request.form["manga_author"]
    artist = request.form["manga_artist"]
    status = request.form["manga_status"]
    # Escape to avoid being pwnd by ATRAN
    description = str(escape(request.form["manga_description"]))
    description = description.replace("\n", "<br>")
    new_manga = Manga(name, url, author, artist, status, cover_url,
        description)

    # Add and commit the new manga into the database
    db.session.add(new_manga)
    db.session.commit()

    # Send a tweet saying that the manga has been created
    if SEND_TWEETS:
        full_url = request.url_root[:-1]
        full_url += url_for("view_manga", manga=url)
        text = 'A new manga "' + name + '" has been released! Check it'
        text += ' out at ' + full_url
        twitter_api.update_status(status=text)

    return redirect(url_for("view_manga", manga=url))
예제 #3
0
    def add_manga(jwt):
        body = request.get_json()

        if not ('title' in body and 'author' in body and 'genre' in body
                and 'rating' in body):
            abort(422)

        try:
            manga = Manga(title=body.get('title'),
                          author=body.get('author'),
                          genre=body.get('genre'),
                          rating=body.get('rating'))
            manga.insert()

            return jsonify({'success': True, 'created': manga.title})
        except BaseException:

            abort(422)
예제 #4
0
    def get(self, name):
        mangatemplate = JINJA_ENVIRONMENT.get_template('templates/manga.html')
        # print (name)
        text = ''
        user = users.get_current_user()
        manga_user = MangaUser.query().filter(
            MangaUser.email == user.nickname()).get()
        logout_url = users.create_logout_url("/")
        if name in manga_user.user_ratings:
            text = 'You have already rated this manga. Do you want to rate this again?'
        else:
            text = 'Rate this manga'
        d = {}
        d['logout'] = logout_url
        favoritetext = ''
        friendrating = 'No ratings yet'
        d['reviews'] = {'No review yet': ''}
        mangaquery = Manga.query().fetch()
        boolean = False
        totalrating = 0
        count = 0
        for i in range(len(mangaquery)):
            if name == mangaquery[i].manga_id:
                manga = mangaquery[i]
                boolean = True
                d['info'] = [
                    manga.imgurl, manga.manga_title, manga.synopsis,
                    manga.manga_id, manga.api_ratings, manga.chapter, text
                ]
                if manga.total_ratings != {}:
                    for key, value in manga.total_ratings.items():
                        if key in manga_user.friends_list:
                            totalrating = totalrating + value
                            count = count + 1
                if manga.reviews != {}:
                    d['reviews'] = manga.reviews
                break
            else:
                boolean = False
        if count != 0:
            averageuserrating = round((totalrating / count), 1)
            friendrating = str(averageuserrating) + '/10'
        d['averageuserrating'] = friendrating

        # print(d['reviews'])
        if boolean == False:
            endpoint_url = 'https://kitsu.io/api/edge/manga/' + name
            response = urlfetch.fetch(endpoint_url)
            content = response.content
            response_as_json = json.loads(content)
            image_url = response_as_json['data']['attributes']['posterImage'][
                'medium']
            titles = response_as_json['data']['attributes']['canonicalTitle']
            synopsis = response_as_json['data']['attributes']['synopsis']
            mangaid = response_as_json['data']['id']
            averagerating = response_as_json['data']['attributes'][
                'averageRating']
            chapter = response_as_json['data']['attributes']['chapterCount']
            if averagerating > 0:
                averageratin = str(round(float(averagerating) / 10, 1)) + '/10'
            else:
                averageratin = 'None'

            d['info'] = [
                image_url, titles, synopsis, mangaid, averageratin, chapter,
                text
            ]

            manga = Manga(
                manga_id=mangaid,
                manga_title=titles,
                imgurl=image_url,
                synopsis=synopsis,
                reviews={},
                total_ratings={},
                api_ratings=averageratin,
                chapter=chapter,
            )
            manga.put()

        if name not in manga_user.favorites:
            favoritetext = 'Add to favorites'
        else:
            favoritetext = 'Added to favorites'
        # print(manga_user)
        d['favoritetext'] = favoritetext
        d['username'] = manga_user.username
        self.response.write(mangatemplate.render(d))