def new_releasing_series(): app.logger.info( '###################################################################') app.logger.info('[SYSTEM] - Starting new releasing series') all_series = Series.query.filter(Series.next_episode_to_air != None).all() media_id = [] for series in all_series: try: diff = (datetime.utcnow() - datetime.strptime( series.next_episode_to_air, '%Y-%m-%d')).total_seconds() # Check if the next episode of the series is releasing in one week or less (7 days) if diff < 0 and abs(diff / (3600 * 24)) <= 7: media_id.append(series.id) except: pass series_in_ptw = db.session.query(Series, SeriesList) \ .join(SeriesList, SeriesList.media_id == Series.id) \ .filter(SeriesList.media_id.in_(media_id), and_(SeriesList.status != Status.RANDOM, SeriesList.status != Status.DROPPED)).all() for info in series_in_ptw: series = Notifications.query.filter_by(user_id=info[1].user_id, media_type='serieslist', media_id=info[0].id) \ .order_by(desc(Notifications.timestamp)).first() if series: payload_series = json.loads(series.payload_json) if int(payload_series['season']) < int(info[0].season_to_air): pass elif int(payload_series['season']) == int(info[0].season_to_air): if int(payload_series['episode']) < int( info[0].episode_to_air): pass else: continue else: continue release_date = datetime.strptime(info[0].next_episode_to_air, '%Y-%m-%d').strftime("%b %d") payload = { 'name': info[0].name, 'release_date': release_date, 'season': '{:02d}'.format(info[0].season_to_air), 'episode': '{:02d}'.format(info[0].episode_to_air) } data = Notifications(user_id=info[1].user_id, media_type='serieslist', media_id=info[0].id, payload_json=json.dumps(payload)) db.session.add(data) db.session.commit() app.logger.info('[SYSTEM] - Finished new releasing series') app.logger.info( '###################################################################')
def follow_status(): try: json_data = request.get_json() follow_id = int(json_data['follow_id']) follow_condition = json_data['follow_status'] except: return '', 400 # Check follow ID exist in User table and status is bool user = User.query.filter_by(id=follow_id).first() if not user or type(follow_condition) is not bool: return '', 400 # Check the status of the follow if follow_condition: # Add the follow current_user.add_follow(user) # Notify the followed user payload = {'username': current_user.username, 'message': '{} is following you.'.format(current_user.username)} notif = Notifications(user_id=user.id, payload_json=json.dumps(payload)) db.session.add(notif) db.session.commit() app.logger.info('[{}] Follow the account with ID {}'.format(current_user.id, follow_id)) else: # Remove the follow current_user.remove_follow(user) # Notify the followed user payload = {'username': current_user.username, 'message': '{} stopped following you.'.format(current_user.username)} notif = Notifications(user_id=user.id, payload_json=json.dumps(payload)) db.session.add(notif) db.session.commit() app.logger.info('[{}] Unfollowed the account with ID {} '.format(current_user.id, follow_id)) return '', 204
def new_releasing_movies(): app.logger.info( '###################################################################') app.logger.info('[SYSTEM] - Starting new releasing movies') all_movies = Movies.query.all() media_id = [] for movie in all_movies: try: diff = (datetime.utcnow() - datetime.strptime( movie.release_date, '%Y-%m-%d')).total_seconds() # Check if he movie released in one week or less (7 days) if diff < 0 and abs(diff / (3600 * 24)) <= 7: media_id.append(movie.id) except: pass movies_in_ptw = db.session.query(Movies, MoviesList) \ .join(MoviesList, MoviesList.media_id == Movies.id) \ .filter(MoviesList.media_id.in_(media_id), MoviesList.status == Status.PLAN_TO_WATCH).all() for info in movies_in_ptw: if not bool( Notifications.query.filter_by(user_id=info[1].user_id, media_type='movieslist', media_id=info[0].id).first()): release_date = datetime.strptime(info[0].release_date, '%Y-%m-%d').strftime("%b %d") payload = {'name': info[0].name, 'release_date': release_date} data = Notifications(user_id=info[1].user_id, media_type='movieslist', media_id=info[0].id, payload_json=json.dumps(payload)) db.session.add(data) db.session.commit() app.logger.info('[SYSTEM] - Finished new releasing anime') app.logger.info( '###################################################################')
def new_releasing_games(): app.logger.info( '###################################################################') app.logger.info('[SYSTEM] - Start adding the new releasing games') all_games = Games.query.all() media_id = [] for game in all_games: try: diff = (datetime.utcnow() - datetime.utcfromtimestamp( int(game.release_date))).total_seconds() # Check if the game release in one week or less (7 days) if diff < 0 and abs(diff / (3600 * 24)) <= 7: media_id.append(game.id) except: pass games_in_ptp = db.session.query(Games, GamesList) \ .join(GamesList, GamesList.media_id == Games.id) \ .filter(GamesList.media_id.in_(media_id), GamesList.status == Status.PLAN_TO_PLAY).all() for info in games_in_ptp: if not bool( Notifications.query.filter_by(user_id=info[1].user_id, media_type='gameslist', media_id=info[0].id).first()): release_date = datetime.utcfromtimestamp(int( info[0].release_date)).strftime("%b %d %Y") payload = {'name': info[0].name, 'release_date': release_date} data = Notifications(user_id=info[1].user_id, media_type='gameslist', media_id=info[0].id, payload_json=json.dumps(payload)) db.session.add(data) db.session.commit() app.logger.info('[SYSTEM] - Finish adding the new releasing games') app.logger.info( '###################################################################')