Beispiel #1
0
    def show_history_csv(self, ch, _user, _groups):
        history = CashPoolHistoryDal.read()
        if not history:
            self.send(ch, messages.NO_RECORD('cash pool'))
            return

        self.send_now(ch, messages.ACKNOWLEDGE())

        csv_file = 'cash_pool_history.csv'
        with open(csv_file, 'wb') as f:
            writer = csv.writer(f)
            writer.writerow(CashPoolHistoryDal.columns)

        lookup = users.UsersDal.read_lookup_table()
        for item in history:
            source, targets, value, currency, reason, user, date = item
            targets = eval(targets)  # pylint: disable=W0123
            if reason == 'REVERT':
                reason = '[REVERTED BY {}]'.format(lookup[user])

            with open(csv_file, 'ab') as f:
                writer = csv.writer(f)
                writer.writerow([
                    lookup[source], [str(lookup[k]) for k in targets], value,
                    currency.upper(), reason, lookup[user], date
                ])

        current_time = time.strftime('%Y-%m-%d %H:%M:%S')
        self.upload_now(ch, 'Cash Pool History for {}'.format(current_time),
                        csv_file, 'csv')

        os.remove(csv_file)
Beispiel #2
0
    def show_history(self, ch, _user, groups):
        history = CashPoolHistoryDal.read()
        if not history:
            self.send(ch, messages.NO_RECORD('cash pool'))
            return

        get_csv = any('csv' in g for g in groups)
        csv_file = 'cash_pool_output.csv'
        entire = any('entire' in g for g in groups)

        if get_csv:
            self.send_now(ch, messages.ACKNOWLEDGE())

            with open(csv_file, 'wb') as f:
                writer = csv.writer(f)
                writer.writerow(CashPoolHistoryDal.columns)
        elif entire:
            self.send(ch, messages.DISPLAYING('history'))
        else:
            self.send(ch, messages.DISPLAYING('recent history'))

        lookup = users.UsersDal.read_lookup_table()

        recent = None if entire else -10
        for item in history[recent:]:
            source, targets, value, currency, reason, user = item
            targets = eval(targets)  # pylint: disable=W0123
            if reason == 'REVERT':
                reason = '[REVERTED BY {}]'.format(lookup[user])

            if get_csv:
                with open(csv_file, 'ab') as f:
                    writer = csv.writer(f)
                    writer.writerow(
                        [lookup[source], [str(lookup[k]) for k in targets],
                         value, currency.upper(), reason, lookup[user]])
                continue

            self.send(ch, messages.SHOW_CASH_POOL_HISTORY_ITEM(
                lookup[source], ' and '.join(lookup[k] for k in targets),
                value, currency.upper(), reason))

        if get_csv:
            current_time = time.strftime('%Y-%m-%d %H:%M:%S')
            self.upload_now(
                ch, 'Cash Pool History for {}'.format(current_time), csv_file,
                'csv')

            os.remove(csv_file)
Beispiel #3
0
    def display(self, ch, _user, groups):
        status = groups[0]
        if status in ('incomplete', 'ongoing'):
            target_directory = ONGOING_DIR
        elif status in ('completed', 'finished'):
            target_directory = COMPLETED_DIR
        else:
            self.send(ch, messages.CONFUSED())
            return

        files = os.listdir(target_directory)
        if not files:
            self.send(ch, 'Sir, no torrents are {}.'.format(status[0]))
            return

        self.send(ch, messages.ACKNOWLEDGE())
        for torrent in sorted(files):
            self.send(ch, torrent)
Beispiel #4
0
    def send_cash(self, ch, user, groups):
        reason, single, _direction, value, currency, _, multiple = groups
        reason = reason[6:] if reason.startswith('jarvis') else reason
        if not currency:
            currency = DEFAULT_CURRENCY.lower()

        single = user if single == 'i' else users.UsersDal.read_by_name(single)

        multiple = helper.language_to_list(multiple)
        for idx, item in enumerate(multiple):
            if item == 'me':
                multiple[idx] = user
            elif item in ('herself', 'himself'):
                multiple[idx] = single
            else:
                multiple[idx] = users.UsersDal.read_by_name(item)

        CashPoolDal.update(single, multiple, int(float(value) * 100), currency)
        CashPoolHistoryDal.create(single, str(multiple), value, currency,
                                  reason.strip(' ,.?!'), user)

        self.send(ch, messages.ACKNOWLEDGE())
Beispiel #5
0
    def do_transactions(send, ch, user, reason, transactions, regex):
        for tx in transactions:
            sender, value, curr, receiver = regex.match(tx).groups()
            curr = curr or DEFAULT_CURRENCY.lower()
            receivers = receiver.split(' ')

            sender = CashPoolHelper.get_real_sender(send, ch, user, sender)
            if not sender:
                return

            for i, recv in enumerate(receivers):
                receivers[i] = CashPoolHelper.get_real_receiver(
                    send, ch, user, sender, recv)
                if not receivers[i]:
                    return

            CashPoolDal.update(sender, receivers, int(float(value) * 100),
                               curr)
            CashPoolHistoryDal.create(sender, str(receivers), value, curr,
                                      reason, user)

            send(ch, messages.ACKNOWLEDGE())
Beispiel #6
0
 def die(self, ch, _user, _groups):
     self.send_now(ch, messages.ACKNOWLEDGE())
     sys.exit(0)
Beispiel #7
0
 def ship_it(self, ch, _user, _groups):
     self.send(ch, messages.ACKNOWLEDGE())
     self.send(ch, random.choice(squirrels))