Exemplo n.º 1
0
def parse_vgo_inventory(data):
    inventory = []

    if data['response']['user_data']['steam_id'] == key_config.steam_id:
        bot_inventory = True
    else:
        bot_inventory = False

    trade_offer_config = configuration.get('trade_offers')

    for item in data['response']['items']:
        parsed_item = Empty()

        parsed_item.name = item['name']
        parsed_item.assetid = item['id']
        parsed_item.icon_url = item['image']['300px']
        parsed_item.price = item['suggested_price_floor'] / 100

        if bot_inventory:
            parsed_item.price = parsed_item.price * float(
                trade_offer_config.bot_percentage)
        else:
            parsed_item.price = parsed_item.price * float(
                trade_offer_config.user_percentage)

        inventory.append(parsed_item)

    return inventory
Exemplo n.º 2
0
def finish_round(winning_alternative):
    db = Session()
    config = configuration.get('roulette')

    for user_bet in db.query(Bet).filter(
            Bet.roulette_round == db.query(Roulette).filter(
                Roulette.id == 1).one().current_round):
        user = db.query(User).filter(User.steamid == user_bet.steamid).one()

        if user_bet.alternative == winning_alternative:
            if winning_alternative == 1 or winning_alternative == 2:
                user.balance += user_bet.amount * float(
                    config.red_black_payout)
                db.commit()

            else:
                user.balance += user_bet.amount * float(config.green_payout)
                db.commit()

        print('user_bet: ' + str(user_bet.alternative))

    print('Winning Alternative: ' + str(winning_alternative))

    roulette = db.query(Roulette).filter(Roulette.id == 1).one()
    roulette.current_round += 1
    db.commit()
Exemplo n.º 3
0
def get_user_steam_inventory(user_id):
    inventory_url = 'http://steamcommunity.com/inventory/{0}/{1}/2?l=english&count=500'

    inventory_data = requests.get(
        inventory_url.format(user_id,
                             configuration.get('website').appid)).json()
    inventory_assets = utilities.parse_steam_inventory(inventory_data)

    return inventory_assets
Exemplo n.º 4
0
def index():

    balance = ''

    if current_user.is_authenticated:
        balance = db.session.query(User).filter(
            User.steamid == current_user.id).one().balance

    return render_template('home.html',
                           template_data=configuration.get('website'),
                           balance=balance)
Exemplo n.º 5
0
def before_first_request():
    roulette.init_roulette()

    scheduler.add_job(func=roulette.time_roulettes,
                      trigger='interval',
                      seconds=1)

    scheduler.add_job(
        func=trade_offers.check_trade_offers,
        trigger='interval',
        seconds=int(
            configuration.get('trade_offers').trade_offer_poll_interval))

    scheduler.start()
Exemplo n.º 6
0
def get_vgo_trade_offer_value(items, bot_inventory):
    items_string = ','.join(map(str, items))

    response = requests.get(
        'https://api-trade.opskins.com/IItem/GetItemsById/v1/?key={0}&item_id={1}'
        .format(configuration.get('keys').vgo_key, items_string)).json()

    value = 0

    for item in response['response']['items']:
        item_price = item['suggested_price_floor']

        item_price = item_price / 100

        if bot_inventory:
            item_price = item_price * float(
                configuration.get('trade_offers').bot_percentage)
        else:
            item_price = item_price * float(
                configuration.get('trade_offers').user_percentage)

        value += item_price

    return value
Exemplo n.º 7
0
from init_app import db, socketio

from models import Empty, Steam_item, User

from handlers import configuration
from handlers import user as user_handler

from functools import wraps

from flask import redirect, request

import json, requests, os

key_config = configuration.get('keys')
website_config = configuration.get('website')

summaries_url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={0}&steamids={1}'
market_url = 'http://steamcommunity.com/market/priceoverview/?appid={0}&currency=1&market_hash_name={1}'


def steamid_to_name(steamid):
    steam_data = requests.get(
        summaries_url.format(key_config.steam_api_key, steamid)).json()

    return steam_data['response']['players'][0]['personaname']


def parse_steam_inventory(inventory_data):

    asset_dict = {}
    inventory_assets = []
Exemplo n.º 8
0
def deposit():
    rule = request.url_rule

    if request.method == 'GET':

        if configuration.get('trade_offers').steam_skins == '1':
            if 'deposit' in rule.rule:
                inventory = get_user_steam_inventory(current_user.id)
            else:
                inventory = get_user_steam_inventory(
                    configuration.get('keys').steam_id)
        else:
            if 'deposit' in rule.rule:
                print('Getting user inventory')

                action = 'deposit'
                inventory = vgo_actions.get_vgo_inventory(current_user.id)
            else:
                print('Getting bot inventory')

                action = 'withdraw'
                inventory = vgo_actions.get_vgo_inventory(
                    configuration.get('keys').steam_id)

        if inventory == []:
            return errors.route_error(
                'Failed to get your inventory\nBecause you have no items or you have no trade.opskins account'
            )

        return render_template(
            'trade_offer.html',
            inventory_data=inventory,
            template_data=configuration.get('website'),
            action=action,
            balance=db.session.query(User).filter(
                User.steamid == current_user.id).one().balance)

    else:

        if configuration.get('trade_offers').vgo_skins == '1':

            if 'deposit' in rule.rule:
                print('User Depositing')

                inventory = vgo_actions.get_vgo_inventory(current_user.id)
                trade_offer_type = Trade_offer_types.deposit
            else:
                print('User Withdrawing')

                inventory = vgo_actions.get_vgo_inventory(
                    configuration.get('keys').steam_id)
                trade_offer_type = Trade_offer_types.withdraw

            items = []

            for item in inventory:
                if str(item.assetid) in request.form:
                    items.append(item.assetid)

            offer_response = vgo_actions.send_trade_offer(
                current_user.id, items, trade_offer_type)

            if offer_response == Sent_trade_offer.success:
                return redirect('/')
            else:
                return offer_response
Exemplo n.º 9
0
from init_app import socketio, db

from sqlalchemy import create_engine

from handlers import bet, configuration

from models import Base, Roulette

import os

timer = 0

config = configuration.get('roulette')


def time_roulettes():
    global timer
    timer += 1

    if timer < int(config.interval):
        socketio.emit('update_time',
                      str(int(config.interval) - timer),
                      broadcast=True)

    if timer == int(config.interval):
        winning_alternative = bet.lottery()
        socketio.emit('run_script', str(winning_alternative), broadcast=True)
        bet.finish_round(winning_alternative)

    if timer == int(config.interval) + 3:
        timer = 0
Exemplo n.º 10
0
from init_app import db

from handlers import configuration, errors
from utilities import parse_vgo_inventory, validate_user_balance, get_vgo_trade_offer_value

from models import Empty, Trade_offer, Trade_offer_types, Sent_trade_offer, User

from flask import render_template

import requests, pyotp

keys_config = configuration.get('keys')
trade_offer_config = configuration.get('trade_offers')


def get_vgo_inventory(steamid):
    inventory_url = 'https://api-trade.opskins.com/ITrade/GetUserInventoryFromSteamId/v1/?key={0}&steam_id={1}&app_id=1'

    response = requests.get(inventory_url.format(keys_config.vgo_key, steamid))

    print('Getting user inventory with ' + response.url)

    if response.status_code == 200:
        print('Successful request')
        return parse_vgo_inventory(response.json())
    else:
        print('Failed request ' + str(response.status_code) + ' for user ' +
              steamid)
        return []

Exemplo n.º 11
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

from models import Trade_offer, Trade_offer_types, User

from handlers import configuration

from vgo import vgo_actions

from utilities import get_vgo_trade_offer_value

import requests, os

key_config = configuration.get('keys')

Session = scoped_session(
    sessionmaker(create_engine(os.environ['DATABASE_URL'])))


def check_trade_offers():
    db = Session()

    for deposit in db.query(Trade_offer).all():

        if deposit.vgo_offer == True:
            state = int(
                requests.get(
                    'https://api-trade.opskins.com/ITrade/GetOffer/v1/?key={0}&offer_id={1}'
                    .format(key_config.vgo_key, deposit.offer_id)).json()
                ['response']['offer']['state'])