Exemple #1
0
 def post(self, ident=None):
     if ident:
         manga = MangaModel.fetch_by_key(ident)
     else:
         manga = MangaModel()
     manga.name = self.request.get('name', '')
     manga.frequency = float(self.request.get('frequency', ''))
     manga.url_scheme = self.request.get('url_scheme', '')
     manga.volume = int(self.request.get('volume', '-1'))
     manga.chapter = int(self.request.get('chapter', '-1'))
     manga.freq_units = self.request.get('freq_units', '')
     manga.countdown = float(self.request.get('countdown', ''))
     manga.update = bool(self.request.get('update', False))
     manga.manga_updates_url = self.request.get('manga_updates_url', '')
     key = manga.put()
     self.response.write(key.urlsafe())
     self.redirect(webapp2.uri_for('home'))
Exemple #2
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))