Exemplo n.º 1
0
def fallback_on_def(request, translate_items):
    need_fallback = []
    for thing_hash, name in translate_items.items():

        if name is None:
            need_fallback.append(thing_hash)

    connection = get_redis_database_connection(request)

    things = Thing.get_many_from_database_by_hash_without_history(need_fallback, connection)

    for thing_hash, thing in things.items():
        translate_items[thing_hash] = thing.FullName

    return translate_items
Exemplo n.º 2
0
def translate(request, hash_list):
    pipe = get_redis_database_connection(request).pipeline()
    for thing_hash in hash_list:
        pipe.get(KEY_THING_LOCALE_THING_NAME.format(request.session['language'], thing_hash))

    db_results = pipe.execute()
    things_with_names = dict(zip(hash_list, db_results))

    if request.session['language'] != 'english':
        things_with_names = try_fallback_english(request, things_with_names)

    things_with_names = fallback_on_def(request, things_with_names)

    things_with_names = {k: v.title() for k, v in things_with_names.items()}

    return things_with_names
Exemplo n.º 3
0
def try_fallback_english(request, translate_items):
    pipe = get_redis_database_connection(request).pipeline()

    need_fallback = []
    for thing_hash, name in translate_items.items():

        if name is None:
            need_fallback.append(thing_hash)
            pipe.get(KEY_THING_LOCALE_THING_NAME.format('english', thing_hash))

    db_results = pipe.execute()

    fallback_names = dict(zip(need_fallback, db_results))

    translate_items = {**translate_items, **fallback_names}

    return translate_items
Exemplo n.º 4
0
def test_app_context():
    a = app.make_app()
    a.config['TESTING'] = True
    a.app_context().push()

    g._database = get_redis_database_connection(db_number=0, redis_client=fakeredis.FakeRedis)

    pipe = g._database.pipeline()

    pipe.set(consts.KEY_CONFIGURATION_PRIME_COST, 300, nx=True)
    pipe.set(consts.KEY_API_VERSION, '1.2', nx=True)
    pipe.set(consts.KEY_API_VERSION_SUPPORTED, '1.1', nx=True)
    pipe.hset(consts.KEY_CONFIGURATION_ORDERS, consts.HASH_KEY_ORDER_TICK_DELAY, '60000')
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MTIME_START, 23)
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MTIME_LENGTH, 3600)
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MTIME_PREABMLE, 7200)
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MTIME_NEXT, 0)
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MTIME_SET, "false")
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_BUY_PRICE_MULTIPLIER, "0.20")
    pipe.hmset(consts.KEY_API_MAINTENANCE_WINDOW, {"Start": "1551049200", "Stop": "1551052800"})

    pipe.hset(consts.KEY_GLITTERBOT_DATA,
              consts.KEY_GLITTERBOT_IGNORE_THINGS, json.dumps(
                ['8697f432058b914ba2b20c5bd6f0678548126e21', 'cdf9187a28bcb1b219a3a4aeaf3c99a65e7eb882'])
              )
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_SELL_PRICE_MULTIPLIER, "0.75")
    pipe.hsetnx(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_MIN_SELL_PRICE_MULTIPLIER, "0.2")
    breakpoints = [
        {'PriceStart': 0, 'PriceStop': 5, 'StockMin': 1000, 'StockMax': 100000, 'CapBuyPrice': 2.5},
        {'PriceStart': 5, 'PriceStop': 25, 'StockMin': 200, 'StockMax': 250, 'CapBuyPrice': 2.75},
        {'PriceStart': 25, 'PriceStop': 50, 'StockMin': 100, 'StockMax': 150, 'CapBuyPrice': 3.0},
        {'PriceStart': 50, 'PriceStop': 100, 'StockMin': 10, 'StockMax': 15, 'CapBuyPrice': 3.5},
        {'PriceStart': 100, 'PriceStop': 100000, 'StockMin': 1, 'StockMax': 15, 'CapBuyPrice': 4.0},
        {'PriceStart': 100000, 'PriceStop': 200000, 'StockMin': 1, 'StockMax': 5, 'CapBuyPrice': 4.5}
    ]
    pipe.hset(consts.KEY_GLITTERBOT_DATA, consts.KEY_GLITTERBOT_PRICEBREAKS, json.dumps(breakpoints))

    thing = Thing("Silver")
    thing.save_to_database(pipe)

    pipe.execute()

    yield a
Exemplo n.º 5
0
import config
from lib.db import get_redis_database_connection
from lib.gwpcc.consts import KEY_COUNTERS_HISTORICAL_THING_VOLUME_TRADED_BY_DATE_AND_ACTION

db = get_redis_database_connection(config.API_DB_CONFIG['u1'])
pipe = db.pipeline()
for action in ['Bought', 'Sold']:
    results = db.zrange(KEY_COUNTERS_HISTORICAL_THING_VOLUME_TRADED_BY_DATE_AND_ACTION.format('2018-11-09', action),
                        0,
                        -1,
                        withscores=True)

    for result in results:
        pipe.zincrby(KEY_COUNTERS_HISTORICAL_THING_VOLUME_TRADED_BY_DATE_AND_ACTION.format('2018-11-11', action),
                     result[0], result[1])

pipe.execute()
Exemplo n.º 6
0
import config
import lib.gwpcc.consts as const
from lib.db import get_redis_database_connection

ok = False
version = None

while not ok:
    version = input('Which version? ')
    if version in config.API_DB_CONFIG:
        ok = True

# Create all needed keys
print('Creating {} configuration data'.format(version))

db = get_redis_database_connection(config.API_DB_CONFIG[version])

pipe = db.pipeline()

# Set version keys
pipe.setnx(const.KEY_API_VERSION, 1.2)
pipe.setnx(const.KEY_API_VERSION_SUPPORTED, 1.1)

# Build maintenance keys
#pipe.setnx(const.KEY_API_MAINTENANCE_MODE, False)
pipe.hsetnx(const.KEY_API_MAINTENANCE_WINDOW, const.HASH_KEY_API_MAINTENANCE_WINDOW_START, int(0))
pipe.hsetnx(const.KEY_API_MAINTENANCE_WINDOW, const.HASH_KEY_API_MAINTENANCE_WINDOW_STOP, int(0))

# Default 1 day delivery for orders.
pipe.hsetnx(const.KEY_CONFIGURATION_ORDERS, const.HASH_KEY_ORDER_TICK_DELAY, 60000)