Skip to content

Commit

Permalink
Merge pull request #43 from JoelNiemela/cleanup
Browse files Browse the repository at this point in the history
Use fstrings instead of %-formatting
  • Loading branch information
pehrsoderman authored Aug 18, 2024
2 parents 00fa596 + 65bdf32 commit 5b35063
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@

_GUESS_MAINCLASS = { 'Java', 'Kotlin', 'Scala' }
_GUESS_MAINFILE = {
'Algol 68', 'APL', 'Bash', 'Crystal', 'Dart', 'Gerbil', 'JavaScript (Node.js)',
'JavaScript (SpiderMonkey)', 'Julia', 'Common Lisp', 'Lua', 'Nim', 'Octave', 'Pascal', 'Perl',
'PHP', 'Python 2', 'Python 3', 'Ruby', 'Rust', 'Simula', 'SNOBOL', 'TypeScript', 'Zig',
'Algol 68', 'APL', 'Bash', 'Crystal', 'Dart', 'Gerbil', 'JavaScript (Node.js)',
'JavaScript (SpiderMonkey)', 'Julia', 'Common Lisp', 'Lua', 'Nim', 'Octave', 'Pascal', 'Perl',
'PHP', 'Python 2', 'Python 3', 'Ruby', 'Rust', 'Simula', 'SNOBOL', 'TypeScript', 'Zig',
}

_HEADERS = { 'User-Agent': 'kattis-cli-submit' }
Expand Down Expand Up @@ -102,7 +102,8 @@ def get_url(cfg, option, default):
if cfg.has_option('kattis', option):
return cfg.get('kattis', option)
else:
return 'https://%s/%s' % (cfg.get('kattis', 'hostname'), default)
hostname = cfg.get('kattis', 'hostname')
return f'https://{hostname}/{default}'


def get_config():
Expand Down Expand Up @@ -292,7 +293,7 @@ def get_submission_url(submit_response, cfg):
if m:
submissions_url = get_url(cfg, 'submissionsurl', 'submissions')
submission_id = m.group(1)
return '%s/%s' % (submissions_url, submission_id)
return f'{submissions_url}/{submission_id}'


def get_submission_status(submission_url, cookies):
Expand All @@ -303,7 +304,7 @@ def get_submission_status(submission_url, cookies):
_RED_COLOR = 31
_GREEN_COLOR = 32
def color(s, c):
return '\x1b[%sm%s\x1b[0m' % (c, s)
return f'\x1b[{c}m{s}\x1b[0m'


def show_judgement(submission_url, cfg):
Expand All @@ -315,16 +316,16 @@ def show_judgement(submission_url, cfg):
testcases_done = status['testcase_index']
testcases_total = status['row_html'].count('<i') - 1

status_text = _STATUS_MAP.get(status_id, 'Unknown status %s' % status_id)
status_text = _STATUS_MAP.get(status_id, f'Unknown status {status_id}')


if status_id < _RUNNING_STATUS:
print('\r%s...' % (status_text), end='')
print(f'\r{status_text}...', end='')
else:
print('\rTest cases: ', end='')

if status_id == _COMPILE_ERROR_STATUS:
print('\r%s' % color(status_text, _RED_COLOR), end='')
print(f'\r{color(status_text, _RED_COLOR)}', end='')
try:
root = fragment_fromstring(status['feedback_html'], create_parent=True)
error = root.find('.//pre').text
Expand All @@ -333,7 +334,7 @@ def show_judgement(submission_url, cfg):
except:
pass
elif status_id < _RUNNING_STATUS:
print('\r%s...' % (status_text), end='')
print(f'\r{status_text}...', end='')
else:
print('\rTest cases: ', end='')

Expand All @@ -348,7 +349,7 @@ def show_judgement(submission_url, cfg):
else:
s += 'x'

print('[%-*s] %d / %d' % (testcases_total, s, testcases_done, testcases_total), end='')
print(f'[{testcases_total: <{s}}] {testcases_done} / {testcases_total}', end='')

sys.stdout.flush()

Expand Down Expand Up @@ -420,9 +421,9 @@ def main():
language = args.language

if language is None:
print('''\
print(f'''\
No language specified, and I failed to guess language from filename
extension "%s"''' % (ext,))
extension "{ext}"''')
sys.exit(1)

files = sorted(list(set(args.files)))
Expand Down

0 comments on commit 5b35063

Please sign in to comment.