def get(self): ownproftemplate = JINJA_ENVIRONMENT.get_template( 'templates/ownprofile.html') user = users.get_current_user() manga_user = MangaUser.query().filter( MangaUser.email == user.nickname()).get() mangausers = MangaUser.query().filter( MangaUser.email != user.nickname()).fetch() h = {} f = {} for i in range(len(manga_user.favorites.keys())): mangaquery = Manga.query().filter( manga_user.favorites.keys()[i] == Manga.manga_id).get() if mangaquery: h[i] = [ mangaquery.imgurl, mangaquery.manga_title, mangaquery.manga_id ] logout_url = users.create_logout_url("/") d = {} for i in range(len(mangausers)): if mangausers[i].username in manga_user.friends_list: f[i] = { 'key': mangausers[i].key, 'username': mangausers[i].username, 'rating': mangausers[i].user_ratings, 'reviews': mangausers[i].user_reviews, 'profile': mangausers[i].profile_img } d = {'username': manga_user.username, 'image': manga_user.profile_img} d['h'] = h d['f'] = f d['logout'] = logout_url self.response.write(ownproftemplate.render(d))
def get(self): threading.Thread(target=Schedule.schedule_update).start() query = Manga.query() for manga in query: try: self.update(manga) except urllib2.HTTPError: logging.error( 'Error while updating {manga}'.format(manga=manga.name)) raise self.redirect(webapp2.uri_for('home'))
def post(self, name): friendtemplate = JINJA_ENVIRONMENT.get_template( 'templates/friend.html') user = users.get_current_user() manga_user = MangaUser.query().filter( MangaUser.email == user.nickname()).get() logout_url = users.create_logout_url("/") mangauser = MangaUser.query().fetch() text = '' d = {} h = {} name1 = int(name) for i in range(len(mangauser)): if mangauser[i].key.id() == name1: d = { 'usernames': mangauser[i].username, 'id': name1, 'friend': mangauser[i], 'image': mangauser[i].profile_img } for j in range(len(mangauser[i].favorites.keys())): mangaquery = Manga.query().filter( mangauser[i].favorites.keys()[j] == Manga.manga_id).get() if mangaquery: h[i] = [ mangaquery.imgurl, mangaquery.manga_title, mangaquery.manga_id ] d['h'] = h if d['usernames'] not in manga_user.friends_list: manga_user.followfriend(d['friend']) text = 'Following. Click to unfollow' else: manga_user.removefriend(d['friend']) text = 'Click to follow user' manga_user.put() #print(manga_user) d['text'] = text d['logout'] = logout_url d['username'] = manga_user.username self.response.write(friendtemplate.render(d))
def get(self): query = Manga.query() for manga in query: self.convert(manga) manga.put()
def get(self): user = users.get_current_user() if user: manga_user = MangaUser.query().filter( MangaUser.email == user.nickname()).get() # If the user is registered... if manga_user: hometemplate = JINJA_ENVIRONMENT.get_template( 'templates/homepage.html') logout_url = users.create_logout_url("/") d = {'logout': logout_url} manga_user = MangaUser.query().filter( MangaUser.email == user.nickname()).get() # print(manga_user) mangausers = MangaUser.query().filter( MangaUser.email != user.nickname()).fetch() # print(mangausers) g = {} e = {} h = {} j = {} k = {} l = {} avg = {} listofrandom = [] list = [] rec = [] mangas = Manga.query().fetch() print(rec) # print(manga_user.favorites.keys()) if mangas != []: for i in range(len(mangas)): if mangas[i].total_ratings.keys() != []: j[mangas[i].manga_id] = [] for i in range(len(mangas)): if mangas[i].total_ratings.keys() != []: for ind in mangas[i].total_ratings.keys(): if ind in manga_user.friends_list: # print(mangas[i].total_ratings) # print(mangas[i].manga_id) j[mangas[i].manga_id].extend( mangas[i].total_ratings.values()) for ind in mangas[i].total_ratings.keys(): if ind == manga_user.username: del j[mangas[i].manga_id] for i in range(len(mangas)): if mangas[i].api_ratings != 'None': apirating = float(mangas[i].api_ratings[:3]) k[mangas[i].manga_id] = apirating if len(k) >= 10: avg = calculateaverage(j) print(avg) count1 = getgoodfrendrec(avg) diff = 0 print(count1) if count1 > 10: rec = getmaxvalues(avg, 10) elif count1 == 0: for i in range(len(mangas)): if mangas[i].api_ratings != 'None': apirating = float( mangas[i].api_ratings[:3]) k[mangas[i].manga_id] = apirating for ind in mangas[i].total_ratings.keys(): if ind == manga_user.username: del k[mangas[i].manga_id] # print(k.values()) rec.extend(getmaxvalues(k, 10)) else: # print(avg.values()) rec = getmaxvalues(avg, count1) # print(rec) diff = 10 - count1 for i in range(len(mangas)): if mangas[i].api_ratings != 'None': apirating = float( mangas[i].api_ratings[:3]) if mangas[i].manga_id not in rec: k[mangas[i].manga_id] = apirating for ind in mangas[i].total_ratings.keys(): if ind == manga_user.username: del k[mangas[i].manga_id] rec.extend(getmaxvalues(k, diff)) print(rec) if mangas != []: for i in range(len(mangas)): if mangas[i].manga_id in rec: l[i] = [ mangas[i].imgurl, mangas[i].manga_title, mangas[i].manga_id ] d['h'] = h d['l'] = l for i in range(len(mangausers)): if mangausers[i].username not in manga_user.friends_list: e[i] = { 'key': mangausers[i].key, 'username': mangausers[i].username, 'rating': mangausers[i].user_ratings, 'reviews': mangausers[i].user_reviews, 'profile': mangausers[i].profile_img } listofrandom.append(i) # print(d['e'][0]['key'].id()) if len(e) - 10 > 0: while len(list) < 10: int = random.choice(listofrandom) if int not in list: list.append(int) for i in range(len(list)): g[i] = e[list[i]] d['e'] = g else: d['e'] = e d['username'] = manga_user.username self.response.write(hometemplate.render(d)) else: self.response.write('Please sign up for our page') else: self.response.write( "Sorry, this page is only for logged in users.")
def post(self, name): # print(type(name)) mangatemplate = JINJA_ENVIRONMENT.get_template('templates/manga.html') user = users.get_current_user() manga_user = MangaUser.query().filter( MangaUser.email == user.nickname()).get() logout_url = users.create_logout_url("/") d = {} totalrating = 0 count = 0 favoritetext = '' d['reviews'] = {'No review yet': ''} friendrating = 'No ratings yet' mangaquery = Manga.query().fetch() for i in range(len(mangaquery)): if name == mangaquery[i].manga_id: manga = mangaquery[i] d['info'] = [ manga.imgurl, manga.manga_title, manga.synopsis, manga.manga_id, manga.api_ratings, manga.chapter ] 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 print(manga.reviews) if count != 0: averageuserrating = round((totalrating / count), 1) friendrating = str(averageuserrating) + '/10' d['averageuserrating'] = friendrating if name not in manga_user.favorites: favoritetext = 'Add to favorites' else: favoritetext = 'Added to favorites' if 'favorites' in self.request.POST: if name not in manga_user.favorites: manga_user.favorites[name] = [manga.manga_title, manga.imgurl] favoritetext = 'Added to favorites' else: del manga_user.favorites[name] favoritetext = 'Add to favorites' manga_user.put() else: rating = self.request.get("rating") reviews = self.request.get('review') if rating == '' and reviews == '': pass elif reviews == '': manga_user.user_ratings[name] = float(rating) manga.total_ratings[manga_user.username] = float(rating) else: manga_user.user_ratings[name] = float(rating) manga_user.user_reviews[name] = reviews manga.total_ratings[manga_user.username] = float(rating) manga.reviews[manga_user.username] = reviews manga_user.put() manga.put() 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['info'].append(text) d['username'] = manga_user.username d['logout'] = logout_url d['favoritetext'] = favoritetext self.response.write(mangatemplate.render(d))
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))
def get(self): manga = MangaModel.query().fetch() self.render_template('manga_list.html', mangas=manga)
def get(self): manga = Manga.query(Manga.countdown < 1.0).fetch() self.render_template('home.html', mangas=manga)