Skip to content

Instantly share code, notes, and snippets.

@highfestiva
Last active June 13, 2023 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save highfestiva/d7a1e48c94e317b77cd916ff5ae164eb to your computer and use it in GitHub Desktop.
Save highfestiva/d7a1e48c94e317b77cd916ff5ae164eb to your computer and use it in GitHub Desktop.
Generates six months of consultancy diary rows
#!/usr/bin/env python3
from datetime import datetime
import pandas as pd
def prt(*args):
print('\t'.join(args), file=wf)
global line_no
line_no += 1
def prt_month():
global month, month_line_no
prt()
prt('Month', f'=SUM(G{month_line_no}:G{line_no})')
while (line_no-3) % 35 != 1:
prt()
month = date.month
month_line_no = line_no
wf = open('consultancy-diary.csv', 'wt')
line_no = week_line_no = month_line_no = 1
prt('Consultancy diary')
prt()
now = datetime.now()
year = now.year
month = now.month
dates = pd.date_range(start=f'{year}-{month}-01', end=f'{year}-{min(12,month+6)}-31')
for date,weekday in zip(dates, dates.day_name()):
if date.month != month:
prt_month()
datecell = str(date).partition(' ')[0] + ' ' + weekday[:3]
week_summary = ''
if weekday == 'Monday':
week_summary = f'=SUM(F{week_line_no}:F{line_no-1})*24'
week_line_no = line_no
elif weekday == 'Sunday':
week_summary = f'=SUM(E{week_line_no}:E{line_no})'
prt(datecell, '', '', '', f'=CEILING((C{line_no}-B{line_no}-D{line_no})*24; 0,25)', '', week_summary, '')
prt_month()
wf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment