def test_change_like_ratio(self): change_like_ratio(0.018) float_ratio = float(str( redis_server.get('LIKE_RATIO').decode('utf-8'))) is_float = isinstance(float_ratio, float) is_correct = float_ratio == 0.018 self.assertTrue(is_float and is_correct)
def test_get_like_ratio(self): current_ratio = float( str(redis_server.get('LIKE_RATIO').decode('utf-8'))) response = get_like_ratio() is_float = isinstance(current_ratio, float) is_also_float = isinstance(response, float) is_equal = response == current_ratio self.assertTrue(is_float and is_also_float and is_equal)
def getTweetId(): temp=redis_server.get("tweet_id") #if tweet_id is null in redis, means the user never tweets if temp is None: #setting the initial tweet id on redis redis_server.set("tweet_id", ID_DEF) tweet_id=ID_DEF else: tweet_id=redis_server.incr("tweet_id",1) return tweet_id
def criteria(): if current_user.is_authenticated: if current_user.username == str( redis_server.get('USERNAME').decode('utf-8')): settings.change_max_views(request.form['views']) settings.change_comments_needed(request.form['comments']) settings.change_like_ratio(request.form['likeratio']) settings.change_view_ratio(request.form['view_ratio']) return redirect('search/dunderbands') else: flash("Admin Access Only") return redirect('users/login') else: flash("Admin Access Only") return redirect('users/login')
def test_get_max_views(self): current_max_views = int( str(redis_server.get('MAX_VIEWS').decode('utf-8'))) self.assertEqual(current_max_views, get_max_views())
def test_change_max_views(self): change_max_views(20000) current_max_views = int( str(redis_server.get('MAX_VIEWS').decode('utf-8'))) self.assertEqual(current_max_views, 20000)
def test_get_comments_needed(self): current_comments = int( str(redis_server.get('MIN_COUNT').decode('utf-8'))) response = get_comments_needed() self.assertEqual(current_comments, response)
def test_change_comments_needed(self): change_comments_needed(2) comments = int(str(redis_server.get('MIN_COUNT').decode('utf-8'))) is_int = isinstance(comments, int) is_correct = comments == 2 self.assertTrue(is_int and is_correct)
def get_view_ratio(self): return float(str(redis_server.get('VIEW_RATIO').decode('utf-8')))
def get_max_views(self): return int(str(redis_server.get('MAX_VIEWS').decode('utf-8')))
def get_comments_needed(self): return int(str(redis_server.get('COMMENTS_REQUESTED').decode('utf-8')))
def get_like_ratio(self): return float(str(redis_server.get('LIKE_RATIO').decode('utf-8')))
def criteria_crunch (dunderSearch, publishedBefore=None, publishedAfter=None, nextToken=None, dunderAnchor=None): if DEBUG == True: print("CRITERIA_CRUNCH") redis_server.set('LOOP', 0) redis_server.set('WHILE', 'GO') while True: redis_server.incr('LOOP') if str(redis_server.get('WHILE').decode('utf-8')) == 'NOGO': print('Redis is a NOGO') return False try: published_before = year_selecter(publishedBefore) except ValueError: print('Default Before') publishedBefore = year_selecter(year=2018) try: published_after = year_selecter(publishedAfter) except ValueError: print('Default After') publishedAfter = year_selecter(year=2016) searchResults = search_getter ( dunderSearch, token=nextToken, related_video=dunderAnchor, published_before=published_before, published_after=published_after) try: nextToken = searchResults['nextPageToken'] except KeyError: nextToken = None # At 10 iterations we start removing words from the search # to increase the chance of receiving a result. if int(str(redis_server.get('LOOP').decode('utf-8'))) == 10: print('Removing Prefix And Continuing Search') dunderSearch = dunderSearch[int(str(redis_server.get('PREFIX').decode('utf-8')))+1:len(dunderSearch)] print(dunderSearch) nextToken = None if int(str(redis_server.get('LOOP').decode('utf-8'))) == 20: print('Removing Country And Continuing Search') dunderSearch = dunderSearch[:-int(str(redis_server.get('COUNTRY').decode('utf-8')))-1] print(dunderSearch) nextToken = None if int(str(redis_server.get('LOOP').decode('utf-8'))) == 25: print('Removing Prefix And Country - Continuing Search') dunderSearch = dunderSearch[int(str(redis_server.get('PREFIX').decode('utf-8')))+1:-int(str(redis_server.get('COUNTRY').decode('utf-8')))-1] print(dunderSearch) nextToken = None if int(str(redis_server.get('LOOP').decode('utf-8'))) == 35: redis_server.set('LOOP', 0) redis_server.set('WHILE', 'NOGO') print('No Results Were Found - It Happens') return False for video in searchResults.get('items', []): videoId = video['id']['videoId'] videoTitle = video['snippet']['title'] isVideo = video['id']['kind'] == 'youtube#video' isClean = title_clean(video['snippet']['title'], includeSearch=dunderSearch) if isVideo and isClean: isFavorite = True doIgnore = True try: for favorite in current_user.favorites: if favorite.videoId == videoId: isFavorite = False else: continue for ignore in current_user.ignore: if ignore.videoId == videoId: doIgnore = False else: continue except AttributeError: print('Unit Test - Current User Is Fraudulent') checkStats = stat_checker(videoId=videoId) try: checkComments = comment_counter(videoId=videoId) != False except HttpError: print('Comments Disabled') checkComments = False if isFavorite and doIgnore and checkStats and checkComments: redis_server.set('WHILE', 'NOGO') currentBand = Albums ( videoId=videoId, nextToken=nextToken, genre=dunderSearch.upper(), videoTitle=videoTitle, topComment=comment_counter(videoId=videoId)) db.session.add(currentBand) db.session.commit() return currentBand
import datetime import random from apiclient.discovery import build from apiclient.errors import HttpError from oauth2client.tools import argparser from app.search_module.models import Albums from app.search_module.strings import no_words, genrePrefix, \ genreMain, countryOfOrigin, my_exciters from app.users_module.models import Favorites, Ignore, Comments from app.users_module.controllers import current_user from app.settings_module.settings_functions import Criteria from app import db, redis_server DEVELOPER_KEY = redis_server.get('DEVELOPER_KEY').decode('utf-8') YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" YOUTUBE = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) settings = Criteria() DEBUG = True SEE_TITLES = False # Add words from lists to database. def word_sort(): for word in no_words: new_word = Comments(word, 'noWord')