-
Notifications
You must be signed in to change notification settings - Fork 0
/
log-update-100-days-of-code.py
47 lines (39 loc) · 1.07 KB
/
log-update-100-days-of-code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
LOG_FILE = 'log.md'
TEMPLATE = """
## Day {0}: April {1}, 2018
**Today's Progress**: Implemented Hello World in {2}
**Link(s) to work**
1. [Hello World in {2}](https://therenegadecoder.com/code/python/hello-world-in-{3}/)
"""
def get_day():
"""
Retrieves the last day from the log and increments it.
:return: the current day
"""
log = open(LOG_FILE, 'r')
lines = log.readlines()
day = 0
for line in reversed(lines):
if 'Day' in line:
day = int(line.split()[2][:-1]) + 1
break
log.close()
return day
def add_record(day, date, language):
"""
Updates the log with a new record.
:param day: the day of code
:param date: the day of the month
:param language: the programming language
:return: nothing
"""
log = open(LOG_FILE, 'a')
log.write(TEMPLATE.format(day, date, language, language.lower()))
log.close()
def main():
date = input('Day of Month: ')
language = input('Language: ')
day = get_day()
add_record(day, date, language)
if __name__ == '__main__':
main()