예제 #1
0
파일: list.py 프로젝트: nyamba/spoj
    def doing(self, args):
        arguments = []
        if args.sort:
            arguments.append('sort=%d' % args.sort)
        if args.page:
            arguments.append('start=%d' % args.page)

        url = _url('problems/main') + ','.join(arguments)

        __, soup = self.get_soup(url)
        headers = []
        headers.append('Solution id(5)')
        if self.is_authenticated():
            headers.append('Solved(4)')
        headers.append('Problem name(1)')
        headers.append('Problem id(2)')
        headers.append('Users(6)')
        headers.append('Success(7)')

        total_col = len(headers)
        def cell_formatter(r, c, data_soup):
            if total_col > 5 and c == 1:
                return '*' if data_soup.find('img') else ''
            else:
                return _(data_soup.text)

        t = PrettyTable(headers)
        t.align["Problem name(1)"] = 'l'
        t.padding_with = 1

        table = soup.findAll('table',{'class': 'problems'})[-1]
        t = text_table(table, t, 1, cell_formatter)
        pager(t.get_string())
예제 #2
0
파일: runner.py 프로젝트: josuesco2/JE
#!/usr/bin/env python

import os
from prettytable import PrettyTable

RESOURCE = '/etc/services'

'CHECK IF THE FILE EXIST'
def exist(obj):
    return True if os.path.isfile(obj) else False

'LETS BUILD A PRETTY TABLE'

table = PrettyTable(['PORT-NAME', 'PORT'])
table.align['PORT-NAME'] = 'l'
table.padding_with = 1

if exist(RESOURCE):
    with open(RESOURCE, 'r') as input:
        for line in input:
            line = line.strip()
            parse = line.split()
            try:
                if parse[0] == '#':
                    continue
                table.add_row([parse[0], parse[1]])
            except IndexError:
                continue

print table