def update(self, arg): self._observer_state = arg f = open("notify.json", "r") d = eval(f.read()) f.close() for e in series_users.keys(): try: if old[e] != new[e]: for user in series_users[e]: # le signe @ pose des problèmes pour JS dans les navigateurs web print(user) try: d[user.split('@')[0]].insert( 0, [ "Nouvelle episode de %s ! " % our_tmdb.Series(e).name, str(datetime.datetime.now().hour) + ":" + str(datetime.datetime.now().minute) ]) except: d[user.split('@')[0]] = [[ "Nouvelle episode de %s ! " % our_tmdb.Series(e).name, str(datetime.datetime.now().hour) + ":" + str(datetime.datetime.now().minute) ]] print(d) except: pass f = open("notify.json", "w") f.write(json.dumps(d)) f.close()
def ajout_serie_utilisateur(idSerie, idUtilisateur): if SeriesData.objects.filter(id_serie=idSerie).count() == 0: a = our_tmdb.Series(idSerie).number_of_episodes s = SeriesData(id_serie=idSerie, liste_utilisateur=[idUtilisateur], nombre_episode=a) s.save() else: l = SeriesData.objects.filter(id_serie=idSerie) l.liste_utilisateur.append(idUtilisateur) l.save()
def home(): if request.method == "POST": if 'email' in request.form.keys(): # login or sign up case if "first_name" in request.form.keys(): # sign up case try: storage_db.ajout_infos_user(request.form["first_name"], request.form["last_name"], request.form["email"], request.form["password"]) except storage_db.LoginAlreadyUsedException as e: return render_template("error.html", error_msg=str(e), login_error=True) # trying to login, works for both new created account or already created account try: user_object = storage_db.authent(request.form["email"], request.form["password"]) current_user = our_tmdb.User(user_object) session["current_user"] = current_user.__dict__ except Exception as e: return render_template("error.html", error_msg=str(e), login_error=True) else: # settings update case current_user = our_tmdb.User(session["current_user"]) current_user.update_settings(**request.form.to_dict()) session["current_user"] = current_user.__dict__ try: current_user = our_tmdb.User(session["current_user"]) except: # if no one is logged in, redirect to login page return redirect(url_for("login")) try: fav_series = [ our_tmdb.Series(i) for i in current_user.favourite_series ] except our_tmdb.tmdbException as e: return render_template("error.html", error_msg=str(e), login_error=False) return render_template("index.html", fav_series=fav_series)
def search(): # Getting the user info that are stored in the session cookie current_user = our_tmdb.User(session["current_user"]) try: # trying to get the series that are already favourite fav_series = [ our_tmdb.Series(i) for i in current_user.favourite_series ] except our_tmdb.tmdbException as e: # showing an error when the API limit is reached return render_template("error.html", error_msg=str(e), login_error=False) if request.method == "GET": id_poster = dict() if request.args["search"]: # if the search query is not empty try: # trying to get the series that are the result of the search search = our_tmdb.Search(request.args["search"]) search_result_series = search.series_poster.keys() id_poster = search.series_poster except our_tmdb.tmdbException as e: # showing an error when the API limit is reached return render_template("error.html", error_msg=str(e), login_error=False) if len(search_result_series) == 0: search_result_code = -1 # -1 for search without results else: search_result_code = 1 # 1 for search with results else: search_result_code = -2 # -2 for empty search return render_template("search_result.html", id_poster=id_poster, search_result_code=search_result_code, fav_series=fav_series)
except: pass f = open("notify.json", "w") f.write(json.dumps(d)) f.close() #dictionnaire old: informations sur les series stockes dans notre serveur, à comparer avec new ci-dessous for e in series_users.keys(): try: f = open(str(e), 'r') old[e] = eval(f.read())["number_of_episodes"] f.close() except: pass #new l'etat actuel des informations sur les series for e in series_users.keys(): new[e] = our_tmdb.Series(e).number_of_episodes #faire appel aux classes subject = Subject() concrete_observer = ConcreteObserver() subject.attach(concrete_observer) subject.subject_state_comparator() #mise à jour notre cache: remplacer les donnees "old" par les nouvelles donnees pour une future comparaison for e in series_users.keys(): f = open(str(e), "w") f.write(str(our_tmdb.Series(e).series_info)) f.close()