Beispiel #1
0
def history(begin=None, end=None, week=False, month=False):
    if week or month:
        end = datetime.datetime.now()
        if week:
            begin = end - datetime.timedelta(days=7)
        if month:
            begin = end - datetime.timedelta(days=28)
    else:
        try:
            begin = utils.parse_date(begin, dtime=True)
        except ValueError:
            return 'Error: unable to parse date %s' % begin
        try:
            end = utils.parse_date(end, dtime=True)
        except ValueError:
            return 'Error: unable to parse date %s' % end
    cd = utils.compose_date
    if not begin <= end:
        return 'Error: %s is not before %s' % (cd(begin), cd(end))
    db = utils.read_db()
    days = [utils.compose_date(begin + datetime.timedelta(days=x)) for x in xrange(0,
        (end-begin).days)]
    matches = ['from: %s to: %s' % (cd(begin), cd(end))]
    for day in days:
        matches.append('%s: %s' % (day, utils.daily_points(day, db)))

    return '\n'.join(matches)
Beispiel #2
0
def history(begin=None, end=None, week=False, month=False):
    if week or month:
        end = datetime.datetime.now()
        if week:
            begin = end - datetime.timedelta(days=7)
        if month:
            begin = end - datetime.timedelta(days=28)
    else:
        try:
            begin = utils.parse_date(begin, dtime=True)
        except ValueError:
            return 'Error: unable to parse date %s' % begin
        try:
            end = utils.parse_date(end, dtime=True)
        except ValueError:
            return 'Error: unable to parse date %s' % end
    cd = utils.compose_date
    if not begin <= end:
        return 'Error: %s is not before %s' % (cd(begin), cd(end))
    db = utils.read_db()
    days = [
        utils.compose_date(begin + datetime.timedelta(days=x))
        for x in xrange(0, (end - begin).days)
    ]
    matches = ['from: %s to: %s' % (cd(begin), cd(end))]
    for day in days:
        matches.append('%s: %s' % (day, utils.daily_points(day, db)))

    return '\n'.join(matches)
Beispiel #3
0
    async def platba(self, ctx, user: discord.User = None, value: int = 0):
        user1_id = str(ctx.message.author)
        user2_id = str(user)
        data = utils.read_db()
        channel = self.bot.get_channel(int(Config.LOG_CHANNEL))
        if user == ctx.message.author:
            await ctx.send('Nemůžeš poslat peníze sám sobě.')
        elif value < 0:
            await ctx.send(f'Hráč {ctx.message.author.mention} se pokusil \
okrást hráče {user.mention}!')
            await channel.send(f'{ctx.message.author.mention} se pokusil při \
platbě zadat zápornou částku.')
        elif value > data['users'][user1_id]:
            await ctx.send(
                f'Hráč {ctx.message.author.mention} nemá dostatečný \
počet peněz, aktuálně má {data["users"][user1_id]} peněz.')
            await channel.send(f'{ctx.message.author.mention} se pokusil při \
platbě zadat vyšší částku, než má.')
        else:
            data['users'][user1_id] -= value
            new_value1 = data['users'][user1_id]
            data['users'][user2_id] += value
            new_value2 = data['users'][user2_id]
            utils.save_db(data)
            await ctx.send(f'Hráči {user.mention} bylo posláno {value} peněz, \
hráč {ctx.message.author.mention} má nyní {new_value1} peněz a hráč \
{user.mention} má nyní {new_value2} peněz.')
            await channel.send(f'Úspěšně provedena platba hráčem \
{ctx.message.author.mention} hráči {user.mention}.')
Beispiel #4
0
 async def reset(self, ctx):
     data = utils.read_db()
     reset_value = data['start-money']
     for key in data['users'].keys():
         data['users'][key] = reset_value
     utils.save_db(data)
     await ctx.send(f'Všem hráčům byly resetovány peníze na {reset_value}.')
Beispiel #5
0
    async def pripsat(self, ctx, user: discord.User = None, value: int = 0):
        user_id = str(user)
        data = utils.read_db()
        if user_id in data['users'].keys():
            data['users'][user_id] += value
        else:
            data['users'][user_id] = data['start-money'] + value
        new_value = data['users'][user_id]
        utils.save_db(data)
        await ctx.send(f'Hráči {user.mention} bylo připsáno {value} peněz, \
nyní má {new_value} peněz.')
Beispiel #6
0
    async def kontrola(self, ctx, user: discord.User = None):
        user_id = str(user)
        data = utils.read_db()
        if user_id in data['users'].keys():
            value = data['users'][user_id]
        else:
            value = data['start-money']
            data['users'][user_id] = value
            utils.save_db(data)

        await ctx.send(f'Hráč {user.mention} má {value} peněz.')
Beispiel #7
0
    async def penize(self, ctx):
        user_id = str(ctx.message.author)
        data = utils.read_db()
        if user_id in data['users'].keys():
            value = data['users'][user_id]
        else:
            value = data['start-money']
            data['users'][user_id] = value
            utils.save_db(data)

        await ctx.send(f'Hráč {ctx.message.author.mention} má {value} peněz.')
Beispiel #8
0
    async def odebrat(self, ctx, user: discord.User = None, value: int = 0):
        user_id = str(user)
        data = utils.read_db()
        if user_id in data['users'].keys():
            new_value = data['users'][user_id] - value
        else:
            new_value = data['start-money'] - value
        if new_value < 0:
            new_value = 0
        data['users'][user_id] = new_value
        utils.save_db(data)
        await ctx.send(f'Hráči {user.mention} bylo odebráno {value} peněz, \
nyní má {new_value} peněz.')
Beispiel #9
0
def prehab(date=None, home=None, work=None, travel=None, other=None):
    try:
        date = utils.parse_date(date)
    except ValueError:
        return 'Error: unable to parse date %s' % date
    db = utils.read_db()
    initial = utils.daily_points(date, db)
    messages = ['%s had %s points' % (date, initial)]
    messages.extend(process_loc(home, db, date, 'home'))
    messages.extend(process_loc(work, db, date, 'work'))
    messages.extend(process_loc(travel, db, date, 'travel'))
    messages.extend(process_loc(other, db, date, 'other'))
    final = utils.daily_points(date, db)
    diff = final - initial
    messages.append('%s added %s points (now has %s)' % (date, diff, final))
    utils.write_db(db)
    return '\n'.join(messages)
Beispiel #10
0
def food(date, breakfast=None, lunch=None, dinner=None, snacks=None):
    try:
        date = utils.parse_date(date)
    except ValueError:
        return 'Error: unable to parse date %s' % date
    db = utils.read_db()
    initial = utils.daily_points(date, db)
    messages = ['%s had %s points' % (date, initial)]
    messages.extend(process_meal(breakfast, db, date, 'breakfast'))
    messages.extend(process_meal(lunch, db, date, 'lunch'))
    messages.extend(process_meal(dinner, db, date, 'dinner'))
    messages.extend(process_meal(snacks, db, date, 'snacks'))
    final = utils.daily_points(date, db)
    diff = final - initial
    messages.append('%s added %s points (now has %s)' % (date, diff, final))
    utils.write_db(db)
    return '\n'.join(messages)
Beispiel #11
0
 async def pripsatstart(self, ctx, value: int = 0):
     data = utils.read_db()
     data['start-money'] = value
     utils.save_db(data)
     await ctx.send(f'Hodnota startovních peněz změněna na {value}.')
Beispiel #12
0
""" Adjust the points value of different foods."""
from formcreator import Form, Text
import utils
db = utils.read_db()
foods_db = db['foods']
def foods(**kwargs):
    msg = []
    change_count = 0
    for key, val in kwargs.items():
        val = val.lstrip(key).strip()
        if not utils.is_point_value(val):
            msg.append('%s: %s is not valid' % (key, val))
            continue
        val_int = int(val)
        if val_int == foods_db[key]:
            continue
        original = foods_db[key]
        foods_db[key] = val_int
        msg.append('%s changed from %s to %s' % (key, original, val_int))
        change_count += 1
    utils.write_db(db)
    msg.append('changed %s of %s items' % (change_count, len(kwargs)))
    return '\n'.join(msg)
foods_form = Form(foods)

for food, points in foods_db.items():
    foods_form += Text('', default='%s %s' % (food, points), cmd_opt=food)
Beispiel #13
0
""" Adjust the points value of different foods."""
from formcreator import Form, Text
import utils
db = utils.read_db()
foods_db = db['foods']


def foods(**kwargs):
    msg = []
    change_count = 0
    for key, val in kwargs.items():
        val = val.lstrip(key).strip()
        if not utils.is_point_value(val):
            msg.append('%s: %s is not valid' % (key, val))
            continue
        val_int = int(val)
        if val_int == foods_db[key]:
            continue
        original = foods_db[key]
        foods_db[key] = val_int
        msg.append('%s changed from %s to %s' % (key, original, val_int))
        change_count += 1
    utils.write_db(db)
    msg.append('changed %s of %s items' % (change_count, len(kwargs)))
    return '\n'.join(msg)


foods_form = Form(foods)

for food, points in foods_db.items():
    foods_form += Text('', default='%s %s' % (food, points), cmd_opt=food)
Beispiel #14
0
##		  of the lugs
## lug_data_q	- is the queue where I put the result of my process
##		  fetching data
lug_db_q = Queue()
lug_data_q = Queue()

### Counter
## num_elem	- is the number of lug read from the db
## num_read	- is the number of result read the the lug_data_q
num_elem = 0
num_read = 0

## Database in ZODB
db, zodb = zodb_conn_open(config.ZODB_DB)

lug_db = read_db()

for row in lug_db.values():
    lug_db_q.put(row)
    num_elem = num_elem + 1

for num in range(config.P_NUMBER):
    lug_db_q.put("DIE")

## Start P_NUMBER process to fetch data
proc_list = list()
for num in range(config.P_NUMBER):
    proc_list.append(Process(target=mp_fill_lug, name=num, args=(lug_db_q, lug_data_q)))
    proc_list[-1].start()