|
| 1 | +import datetime |
| 2 | +import os |
| 3 | + |
| 4 | +README = 'README.md' |
| 5 | +DAY_ZERO = datetime.datetime(2017, 3, 29) # = PyBites 100 days :) |
| 6 | +NUM_DAYS = 100 |
| 7 | +NUM_WIDTH = 3 |
| 8 | +TITLE = 'PyBites 100 Days Of Code Challenge' |
| 9 | +HEADER = '''## {} |
| 10 | +
|
| 11 | +Inpired by [Join the #100DaysOfCode](https://medium.freecodecamp.com/join-the-100daysofcode-556ddb4579e4#.qmiel1bhd). |
| 12 | +
|
| 13 | +### Progress Log\n\n'''.format(TITLE) |
| 14 | +DAY = '* Day {0} - {1}: [SHORT_TITLE_SCRIPT]({0}) - learning: SUMMARY_YOUR_LEARNING\n' |
| 15 | +INIT_FILE = '__init__.py' |
| 16 | +AUTHOR = "__author__ = 'PyBites'\n" |
| 17 | + |
| 18 | + |
| 19 | +def gen_days(): |
| 20 | + '''Generate day range 001...100''' |
| 21 | + for day in range(1, NUM_DAYS + 1): |
| 22 | + yield str(day).zfill(NUM_WIDTH) |
| 23 | + |
| 24 | + |
| 25 | +def get_date(day): |
| 26 | + '''Get date by offsetting nth day from day 0''' |
| 27 | + date = DAY_ZERO + datetime.timedelta(int(day)) |
| 28 | + return date.strftime('%b %d, %Y') |
| 29 | + |
| 30 | + |
| 31 | +def create_readme(): |
| 32 | + '''Create readme file with progress log template''' |
| 33 | + with open(README, 'w') as f: |
| 34 | + f.write(HEADER) |
| 35 | + for d in gen_days(): |
| 36 | + date = get_date(d) |
| 37 | + f.write(DAY.format(d, date)) |
| 38 | + |
| 39 | + |
| 40 | +def create_init(path): |
| 41 | + '''Create init file so each day dir is package, |
| 42 | + and gets committed to git from the start''' |
| 43 | + initfile = os.path.join(path, INIT_FILE) |
| 44 | + with open(initfile, 'w') as f: |
| 45 | + f.write(AUTHOR) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == '__main__': |
| 49 | + if os.path.isfile(README): |
| 50 | + print('README already created') |
| 51 | + else: |
| 52 | + print('Creating README') |
| 53 | + create_readme() |
| 54 | + |
| 55 | + dirs = [d for d in gen_days() if not os.path.isdir(d)] |
| 56 | + if not dirs: |
| 57 | + print('All 100 days directories already created') |
| 58 | + else: |
| 59 | + print('Creating missing day directories') |
| 60 | + for d in dirs: |
| 61 | + os.makedirs(d) |
| 62 | + create_init(d) |
0 commit comments