Exemplo n.º 1
0
def profile():
    # get logged in user entries
    results = UserLikes.query.filter_by(userId=current_user.id)
    names = []
    genres = []
    gb = giantbomb.Api(config.api_key,'API test')
    count = 0
    for result in results:
        try:
            game = gb.get_game(result.gameId)
            gen = game.genres[0].name
            count +=1
        except giantbomb.GiantBombError: #probably a residual ID from the CSV, just skip it
            continue
        names.append(game.name)
        
        if gen not in genres:
            if not gen is None:
                genres.append(gen)
    # returns names to profile.html to populate info
    return render_template('profile.html', name=current_user.name,titles=names,count=count, genre=genres)



    
Exemplo n.º 2
0
    return datetime.datetime.strptime(date_time, "%Y-%m-%d %H:%M:%S")


argv = sys.argv[1:]
opts, args = getopt.getopt(argv, ":o:", ['offset'])

if opts.__len__() != 0:
    if opts[0][0] == '-o':
        offset = int(opts[0][1])
    else:
        offset = 0
else:
    offset = 0

logging.basicConfig(filename='user_reviews_giantbomb.log', level=logging.DEBUG)
gb = giantbomb.Api(os.environ['API_KEY'], os.environ['USER_AGENT'])
client = MongoClient(os.environ["MONGODB_HOST"],
                     username=os.environ['MONGODB_USER'],
                     password=os.environ['MONGODB_PASS'],
                     authSource=os.environ['MONGODB_DB'],
                     authMechanism=os.environ['MONGODB_AUTH'])

db = client[os.environ['MONGODB_DB']]
user_reviews = db["user_reviews"]

x = gb.get("/user_reviews", {"offset": offset})

total = x['number_of_total_results']
limit = x['limit']

logging.info("=============================================================")
Exemplo n.º 3
0
import sys

sys.path.append('giantbomb')  # for importing modules in other folders

from giantbomb import giantbomb  # the 'giantbomb' module is in the src folder

giantBomb = giantbomb.Api("8b696cf1b3bd34411ad61fe5abf3aae480ebe3e4")

results = giantBomb.search('Yogventures')

test = giantBomb.getGame(results[0])

for i in test.deck:

    print i

#print test
Exemplo n.º 4
0
def home():
    # Needs giantbomb api key
    gb = giantbomb.Api(config.api_key,'API test')
    # Reads a random game from the catalog
    with open('video_game.csv') as f:
        reader = csv.reader(f)
        row = random.choice(list(reader))
    game_lookup = row[1]

    # Giantbomb-Redux API method call
    # returns a list object
    results = gb.search(game_lookup)
    game_data = gb.get_game(results[0])

    #If game_data return was NONE
    if game_data.id is None:
        gid = "N/A"
    else: 
        gid = game_data.id

    if game_data.original_release_date is None:
        release = "N/A"
    else:
        release = game_data.original_release_date
    
    if game_data.publishers is None:
        pub = "N/A"
    else:
        pub = game_data.publishers[0]['name']

    if game_data.genres is None:
        genre = "N/A"
    else:
        genre = game_data.genres[0].name

    if game_data.description is None:
        trunc_soup = "N/A"
    else:
        # Game description returned as html txt
        htmltxt = game_data.description
        # BeatufiulSoup returns clean text 
        soup = BeautifulSoup(htmltxt, 'lxml').text
        # Remove first 8 characters of Description ==> Overview
        c_soup = soup[8:]
        #Truncate the length of descritption
        trunc_soup = (c_soup[:250]) if len(soup) > 1000 else c_soup
    # Game object being passed to main.html   
    game = [game_data.name, release, pub,
            game_data.image.medium_url, genre, trunc_soup, gid]
    # If user clicked the like button, POST sends back data
    if request.method == "POST":
        uId=current_user.id
        # Object return is dictionary
        dict_ret= request.form.to_dict()
        # Iterate through dictinary to retrieve val, holds gameId string
        key,val = next(iter(dict_ret.items()))
        # gameId to integer
        gId=int(val)
        # check if UserLikes Table already contains the entry
        if not UserLikes.query.filter_by(userId=current_user.id, gameId=gId).first():
        # add entry to table  
            uLikes= UserLikes(userId=uId, gameId=gId)
            db.session.add(uLikes)
            db.session.commit()
        # go to home page to get new game suggestion
        redirect(url_for('main.home'))

    return render_template('main.html', name=current_user.name, game=game)