Skip to content

Commit 77cedb5

Browse files
committed
Update main.py with csv read/write functionality.
1 parent fddfa6f commit 77cedb5

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

input.csv

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Amoxicillin 500 mg: Take 1 capsule by mouth every 8 hours.
2+
Metformin 500 mg: Take 1 tablet by mouth twice daily with meals.
3+
Lisinopril 10 mg: Take 1 tablet by mouth once daily.
4+
Atorvastatin 20 mg: Take 1 tablet by mouth once daily in the evening.
5+
Omeprazole 20 mg: Take 1 capsule by mouth once daily before breakfast.
6+
Levothyroxine 50 mcg: Take 1 tablet by mouth once daily on an empty stomach.
7+
Hydrochlorothiazide 25 mg: Take 1 tablet by mouth once daily in the morning.
8+
Gabapentin 300 mg: Take 1 capsule by mouth three times daily.
9+
Albuterol Inhaler: Inhale 2 puffs by mouth every 4-6 hours as needed for wheezing.
10+
Ibuprofen 400 mg: Take 1 tablet by mouth every 6 hours as needed for pain.
11+
Sertraline 50 mg: Take 1 tablet by mouth once daily.
12+
Amlodipine 5 mg: Take 1 tablet by mouth once daily.
13+
Prednisone 10 mg: Take 1 tablet by mouth once daily for 5 days.
14+
Ciprofloxacin 500 mg: Take 1 tablet by mouth every 12 hours for 7 days.
15+
Clonazepam 0.5 mg: Take 1 tablet by mouth twice daily.
16+
Montelukast 10 mg: Take 1 tablet by mouth once daily in the evening.
17+
Tramadol 50 mg: Take 1 tablet by mouth every 4-6 hours as needed for pain.
18+
Fluoxetine 20 mg: Take 1 capsule by mouth once daily.
19+
Metoprolol 50 mg: Take 1 tablet by mouth twice daily.
20+
Furosemide 40 mg: Take 1 tablet by mouth once daily in the morning.
21+
Lorazepam 1 mg: Take 1 tablet by mouth every 8 hours as needed for anxiety.
22+
Simvastatin 20 mg: Take 1 tablet by mouth once daily in the evening.
23+
Doxycycline 100 mg: Take 1 tablet by mouth twice daily for 10 days.
24+
Trazodone 50 mg: Take 1 tablet by mouth at bedtime.
25+
Warfarin 5 mg: Take 1 tablet by mouth once daily.
26+
Zolpidem 10 mg: Take 1 tablet by mouth at bedtime as needed for sleep.
27+
Cyclobenzaprine 10 mg: Take 1 tablet by mouth three times daily.
28+
Bupropion 150 mg: Take 1 tablet by mouth once daily.
29+
Meloxicam 15 mg: Take 1 tablet by mouth once daily.
30+
Ranitidine 150 mg: Take 1 tablet by mouth twice daily.

main.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def get_input():
1212
try:
1313
value = int(
1414
input(
15-
"Enter [1] for a single sig. Enter [2] for bulk sigs via .csv file: "
15+
"Enter 1 for a single sig. Enter 2 for bulk sigs via .csv file: "
1616
)
1717
)
18-
if value not in (1, 2):
19-
pass
20-
else:
18+
if value in (1, 2):
2119
return value
20+
else:
21+
print("Invalid value. Enter either a 1 or 2 to continue.")
2222
except ValueError:
23-
pass
23+
print("Invalid value enter a 1 or 2 to continue.")
2424

2525

2626
def generate_output(n):
@@ -35,12 +35,18 @@ def generate_output(n):
3535
" "
3636
)
3737
if inputfile.endswith(".csv") and outputfile.endswith(".csv"):
38-
with open(inputfile, "r") as file:
39-
print(file)
38+
with open(inputfile, "r") as infile, open(outputfile, "w", newline='') as outfile:
39+
reader = csv.reader(infile)
40+
writer = csv.writer(outfile)
41+
for row in reader:
42+
parsed_sig = SigParser().parse(row[0])
43+
writer.writerow([parsed_sig])
44+
print(f"Output written to {outputfile}")
45+
break
4046
else:
4147
print("Both files must end with .csv. Please try again.")
4248
except ValueError:
43-
pass
49+
print("Invalid. Enter input and output file names separated by a space.")
4450
except FileNotFoundError:
4551
print("Input file not found. Please try again.")
4652
pass

0 commit comments

Comments
 (0)