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()
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 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)
def get(self, ident): manga = MangaModel.fetch_by_key(ident) subject = 'Deleted {manga} from datastore'.format(manga=manga.name) html_message = self.render_template('delete_email.html', write=False, item=manga) send_mail(subject, html=html_message) self.response.write(html_message) manga.key.delete() self.redirect(webapp2.uri_for('home'))
def get(self, ident): manga = Manga.fetch_by_name_or_key(ident) chapter = int(self.request.get('chapter', -1)) volume = int(self.request.get('volume', -1)) if chapter > -1: manga.chapter = chapter if volume > -1: manga.volume = volume manga.put() self.redirect(webapp2.uri_for('home'))
def get(self, ident): manga = Manga.fetch_by_name_or_key(ident) if manga.prev_chapter >= 0: manga.chapter = manga.prev_chapter manga.prev_chapter = -1 if manga.prev_volume >= 0: manga.volume = manga.prev_volume manga.prev_volume = -1 manga.put() self.redirect(webapp2.uri_for('home'))
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 get(self, ident=None): if ident: manga = MangaModel.fetch_by_name_or_key(ident) seed = None # If we were not given a manga or could not find the one we were given. if not ident or not manga: manga = MangaModel() seed = random() self.render_template('manga.html', manga=manga, seed=seed)
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))
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 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'))
def get(self): manga = Manga.query(Manga.countdown < 1.0).fetch() self.render_template('home.html', mangas=manga)
def get(self, ident): manga = Manga.fetch_by_name_or_key(ident) self.update(manga) self.redirect(webapp2.uri_for('home'))
def get(self): manga = MangaModel.query().fetch() self.render_template('manga_list.html', mangas=manga)
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): 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))