示例#1
0
def initmovies(movies_col):
    movies = []
    mongo = list(movies_col.find())
    for i in mongo:
        movies.append(
            classes.Movie(i["_id"], i["Title"], i["Genre"], i["Year"],
                          i["Server"]))
    return movies
示例#2
0
def getRand(dataset, basename='title', opener='zcat ', allowEmptyAttr=False):
    check = checkDb('')
    if check[-15:] == msg.datacheckpassed[-15:]:
        pass
    else:
        return checkDb('')

    if dataset[:5] == 'local':
        opener, filename = 'cat ', chat.path + 'liked.movies.txt'
        if not os.path.isfile(filename):
            return msg.gotnothing
    elif dataset == 'watchlist':
        opener, filename = 'cat ', chat.path + 'watch.list.txt'
        if not os.path.isfile(filename):
            return msg.gotnothing
    else:
        if dataset[:7] != 'ratings':
            if dataset == 'anymovie':
                allowEmptyAttr = True
            basename, dataset = 'movie', 'basics'

        filename = 'data/' + basename + '.' + dataset + '.tsv.gz'

    cmd = opener + filename + '| wc -l'
    with os.popen(cmd) as p:
        number_of_lines = p.read().rstrip()

    json = {}

    while not set(['genre', 'keywords', 'actor', 'director']) <= set(
            json.keys()):
        cmd = opener + filename + '| sed -n "`shuf -i1-' + number_of_lines + ' -n1`p"'
        with os.popen(cmd) as p:
            random_entry = p.read().rstrip()

        if random_entry[0:2] == 'tt':
            titleId = random_entry.split()[0]
            random_movie = classes.Movie(titleId, chat.Id)
            json = random_movie.json
            if json['@type'] != 'Movie':
                json = {}
                continue
            if allowEmptyAttr:
                break
        else:
            return

    if dataset == 'localrr':
        movie = recommend()
        if type(movie) == classes.Movie:
            output = msg.similarto.format(random_movie.name,
                                          random_movie.director)
            output += movie.info
            return output
        else:
            return msg.gotnothing

    return random_movie.info
示例#3
0
def massLike(target=''):
    if target == '':
        return msg.emptylist
    elif target == 'latest':
        filename = chat.path + 'liked.movies.txt.lst'
        if not os.path.isfile(filename):
            return msg.gotnothing
        cmd = 'cut -f1 ' + filename
        with os.popen(cmd) as p:
            target = p.read()
    elif target == 'backup':
        filename = 'movies.bak'
        if not os.path.isfile(filename):
            return msg.gotnothing
        cmd = 'cut -f1 ' + filename
        with os.popen(cmd) as p:
            target = p.read()

    Nm, Nd, Na, Ng, Nk = 0, 0, 0, 0, 0

    for i in target.split():
        i = classes.Movie(i, chat.Id)

        if i.json['@type'] == 'Movie':
            like('')
            Nm += 1
            director = i.director
            if director:
                Nd += len(i.director.split(','))
            actor = i.actor
            if actor:
                Na += len(i.actor.split(','))
            genre = i.genre
            if genre:
                Ng += len(i.genre.split(','))
            keywords = i.keywords
            if keywords:
                Nk += len(i.keywords.split(','))

    output = msg.donefetching.format(Nm, Nd, Na, Ng, Nk)

    return output
示例#4
0
def dbFind(query, category='tt'):
    if query == '':
        return msg.missingarg
    else:
        q = 0
        if '+' in query:
            query = query.split('+')
            q += int(query[1])
            query = query[0].rstrip()

    URL = 'https://www.imdb.com/find?s=' + category + '&q=' + query.replace(
        " ", "+")

    if category == 'tt':
        cmd = 'curl -Ls "' + URL + '" | grep -Eo \'/title/tt[0-9]+/\' | uniq'
    if category == 'nm':
        cmd = 'curl -Ls "' + URL + '" | grep -Eo \'/name/nm[0-9]+/\' | uniq'

    with os.popen(cmd) as p:
        output = p.read().splitlines()

    if len(output) == 0 or len(output) <= q:
        return msg.notfound

    from classes import most_recent
    if chat.Id in most_recent:
        title = most_recent[chat.Id]
        if title != None and title.titleId in output:
            output.remove('/title/' + title.titleId + '/')

    for i in output[q:]:
        if category == 'tt':
            titleId = i.split('/')[-2]
            movie = classes.Movie(titleId, chat.Id)
            if movie.json['@type'] != 'Movie': continue

            return movie.info

        elif category == 'nm':

            return str('https://www.imdb.com' + i)
示例#5
0
def get_movie(message):
    string_split = shlex.split(message)
    string_split.remove('<3add_movie')
    movie = classes.Movie("", string_split[0], string_split[1].lower(),
                          int(string_split[2]), 0)
    return movie
示例#6
0
def recommend(target=''):
    if target == '':
        pass

    from classes import most_recent

    if chat.Id not in most_recent or not most_recent[chat.Id]:
        return msg.forgetful

    prev = most_recent[chat.Id]
    recs = most_recent[chat.Id].recs

    if recs == []:
        return msg.gotnothing

    from random import shuffle

    shuffle(recs)

    filename = chat.path + 'liked.movies.txt'
    if os.path.isfile(filename):
        with open(filename) as f:
            f = f.read().splitlines()
            N = len(f)
            for i in range(len(f)):
                f[i] = f[i].split()[0]
            liked = f
    else:
        liked = []

    filename = chat.path + 'watch.list.txt'
    if os.path.isfile(filename):
        with open(filename) as f:
            f = f.read().splitlines()
            for i in range(len(f)):
                f[i] = f[i].split()[0]
            watch = f
    else:
        watch = []

    filename = chat.path + 'recs.list.txt'
    if os.path.isfile(filename):
        with open(filename) as f:
            f = f.read().splitlines()
            for i in range(len(f)):
                f[i] = f[i].split()[0]
            recent = f
    else:
        recent = []

    N = int(N**1.6)
    N = min([N + 4, 100])
    N = str(N)

    for r in recs:
        if r in liked or r in watch or r in recent:
            continue
        r = classes.Movie(r, chat.Id)

        if r.json['@type'] == 'Movie':
            classes.most_recent[chat.Id] = r
            movie = r

            filename = chat.path + 'recs.list.txt'
            with open(filename, 'a') as o:
                o.write(movie.titleId + '\t' + movie.name + '\n')

            cmd = 'temp=`mktemp`;'
            cmd += 'tail -' + N + ' ' + filename + ' >$temp;'
            cmd += 'mv $temp ' + filename
            os.system(cmd)

            if target == 'direct':
                output = msg.similarto.format(prev.name, prev.director)
                output += movie.info
                return output
            else:
                return movie

    return msg.gotnothing
示例#7
0
import classes
import fresh_tomatoes

toy_story = classes.Movie("Toy Story", "Toys come to life.", "http://a.dilcdn.com/bl/wp-content/uploads/sites/8/2013/02/toy_story_wallpaper_by_artifypics-d5gss19.jpg", "https://www.youtube.com/watch?v=4KPTXpQehio")
school_of_rock = classes.Movie("School of Rock", "Jack Black.", "http://www.gstatic.com/tv/thumb/movieposters/33094/p33094_p_v7_aa.jpg", "https://www.youtube.com/watch?v=3PsUJFEBC74")

movies = [toy_story, school_of_rock]
#fresh_tomatoes.open_movies_page(movies)

print classes.Movie.__doc__


#print toy_story.storyline
#toy_story.showTrailer()