GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExportCommand.default()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 18
rs 9.2
1
import csv
2
import os
3
4
5
from . import BotCommand
6
7
8
class ExportCommand(BotCommand):
9
    command = '/export'
10
11
    def default(self, message):
12
        from tempfile import mkstemp
13
14
        tab = self.get_tab(message.chat.id)
15
16
        csvhandle, csvfilename = mkstemp(suffix='.csv', prefix='verese-export-')
17
        with os.fdopen(csvhandle, 'wb') as csvfile:
18
            csvwriter = csv.writer(csvfile, delimiter=',')
19
            csvwriter.writerow(['Person', 'Amount', 'Date', 'Reason'])
20
            for entry in tab.entries:
21
                user = self._db.root.users[entry.user_id]
22
                user_repr = '{} {}'.format(user.first_name, user.last_name).strip()
23
                row = [u'{}'.format(x).encode('utf-8')
24
                       for x in [user_repr, entry.amount, entry.date, entry.reason]]
25
                csvwriter.writerow(row)
26
27
        self.bot.sendDocument(chat_id=message.chat.id, document=open(csvfilename, 'rb'))
28
        os.unlink(csvfilename)
29