Add support for Python

This commit is contained in:
William Brawner 2022-12-06 21:59:46 -07:00
parent c02cab1075
commit 2b8b71eb61
3 changed files with 40 additions and 0 deletions

View file

@ -51,6 +51,37 @@ class Kotlin(Language):
""".format(day=day) """.format(day=day)
class Python(Language):
input_path = 'python'
src_path = 'python'
def src_file_name(self, day):
return "day{}.py".format(day)
def format_src(self, day):
return """#!/usr/bin/env python3
from util import read_input
def part1(input):
pass
def part2(input):
pass
test_input = read_input("Day{day}_test")
assert 0 == part1(test_input)
assert 0 == part2(test_input)
real_input = read_input('Day{day}')
print(part1(real_input))
print(part2(real_input))
""".format(day=day)
class Rust(Language): class Rust(Language):
input_path = 'rust' input_path = 'rust'
src_path = 'rust/src/bin' src_path = 'rust/src/bin'
@ -92,6 +123,7 @@ if not session_cookie.startswith('session='):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-d', '--day', type=int, required=True) parser.add_argument('-d', '--day', type=int, required=True)
parser.add_argument('--kotlin', action='store_true') parser.add_argument('--kotlin', action='store_true')
parser.add_argument('--python', action='store_true')
parser.add_argument('--rust', action='store_true') parser.add_argument('--rust', action='store_true')
args = parser.parse_args() args = parser.parse_args()
@ -105,6 +137,9 @@ languages = []
if args.kotlin: if args.kotlin:
languages.append(Kotlin()) languages.append(Kotlin())
if args.python:
languages.append(Python())
if args.rust: if args.rust:
languages.append(Rust()) languages.append(Rust())

2
python/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
__pycache__
*.txt

3
python/util.py Normal file
View file

@ -0,0 +1,3 @@
def read_input(path):
with open(path + '.txt', 'r') as input_file:
return input_file.readlines()