development #6
83
main.py
83
main.py
@@ -65,51 +65,41 @@ def get_worklogs(issues):
|
|||||||
worklogs.append(worklog)
|
worklogs.append(worklog)
|
||||||
return worklogs
|
return worklogs
|
||||||
|
|
||||||
def get_days(day, weeks_back=WEEKS_BACK):
|
def get_days(day):
|
||||||
if WEEKS_BACK:
|
if WEEKS_BACK:
|
||||||
day = day - datetime.timedelta(weeks=weeks_back)
|
day = day - datetime.timedelta(weeks=WEEKS_BACK)
|
||||||
|
|
||||||
year, weeknum, day_of_week = day.isocalendar()
|
year, weeknum, day_of_week = day.isocalendar()
|
||||||
days = []
|
while day_of_week != 1:
|
||||||
days.append(str(day))
|
|
||||||
while day_of_week > 1:
|
|
||||||
day = day - datetime.timedelta(days=1)
|
day = day - datetime.timedelta(days=1)
|
||||||
day_of_week -= 1
|
year, weeknum, day_of_week = day.isocalendar()
|
||||||
|
days = []
|
||||||
|
current_month = day.month
|
||||||
|
while day_of_week <= 7:
|
||||||
|
if day.month != current_month:
|
||||||
|
break # Stop collecting if month changes
|
||||||
days.append(str(day))
|
days.append(str(day))
|
||||||
return days
|
day = day + datetime.timedelta(days=1)
|
||||||
|
day_of_week += 1
|
||||||
# NOT FUNCTIONAL
|
|
||||||
def get_weeks(day, worklogs, weeks=list()):
|
days_second_part = []
|
||||||
year, weeknum, day_of_week = day.isocalendar()
|
if day_of_week <= 7: # This condition means the loop ended because the month changed
|
||||||
days = get_days(day, weeks_back=0)
|
next_month = day.month
|
||||||
tickets = get_week_tickets(worklogs, days)
|
while day_of_week <= 7 and day.month == next_month:
|
||||||
weeks.append(tickets)
|
days_second_part.append(str(day))
|
||||||
if weeknum != 0:
|
day = day + datetime.timedelta(days=1)
|
||||||
days = get_days(day, weeks_back=1)
|
day_of_week += 1
|
||||||
get_weeks(days[0], worklogs, weeks)
|
|
||||||
return weeks
|
return days, days_second_part
|
||||||
|
|
||||||
# TODO: implement this
|
|
||||||
def get_days_range(date_from, date_to):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_week_tickets(worklogs, days):
|
def get_week_tickets(worklogs, days):
|
||||||
this_week_tickets = []
|
this_week_tickets = []
|
||||||
for worklog in worklogs:
|
for worklog in worklogs:
|
||||||
worklog_date = datetime.datetime.strptime(worklog["date"].split('T')[0], '%Y-%m-%d').date()
|
worklog_date = datetime.datetime.strptime(worklog["date"].split('T')[0], '%Y-%m-%d').date()
|
||||||
current_month = get_max_month(days)
|
if str(worklog_date) in days:
|
||||||
worklog_month = str(worklog_date).split('-')[1]
|
|
||||||
if str(worklog_date) in days and int(worklog_month) == current_month:
|
|
||||||
this_week_tickets.append(worklog)
|
this_week_tickets.append(worklog)
|
||||||
return this_week_tickets
|
return this_week_tickets
|
||||||
|
|
||||||
def get_max_month(days):
|
|
||||||
max = 0
|
|
||||||
for day in days:
|
|
||||||
month = int(day.split('-')[1])
|
|
||||||
if month > max:
|
|
||||||
max = month
|
|
||||||
return max
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print('The script starts its work...')
|
print('The script starts its work...')
|
||||||
|
|
||||||
@@ -117,20 +107,37 @@ def main():
|
|||||||
issues = get_issues(username)
|
issues = get_issues(username)
|
||||||
worklogs = get_worklogs(issues)
|
worklogs = get_worklogs(issues)
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
days = get_days(today)
|
days, days_second_part = get_days(today)
|
||||||
worklogs = get_week_tickets(worklogs, days)
|
week_worklogs = get_week_tickets(worklogs, days)
|
||||||
omnimat_string = ""
|
omnimat_string = ""
|
||||||
|
|
||||||
for worklog in worklogs:
|
for worklog in week_worklogs:
|
||||||
if worklog["ticket_id"] not in omnimat_string:
|
if worklog["ticket_id"] not in omnimat_string:
|
||||||
omnimat_string += worklog["ticket_id"] + '\n'
|
omnimat_string += worklog["ticket_id"] + '\n'
|
||||||
|
|
||||||
|
if days_second_part:
|
||||||
|
second_omnimat_string = ""
|
||||||
|
worklogs_second_part = get_week_tickets(worklogs, days_second_part)
|
||||||
|
for worklog in week_worklogs:
|
||||||
|
if worklog["ticket_id"] not in second_omnimat_string:
|
||||||
|
second_omnimat_string += worklog["ticket_id"] + '\n'
|
||||||
|
|
||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
print('Issues of the user:')
|
print('Issues of the user:')
|
||||||
print(json.dumps(issues, indent=4))
|
print(json.dumps(issues, indent=4))
|
||||||
print(f"Worklogs for the current week:")
|
print(f"Worklogs for the week:")
|
||||||
print(json.dumps(worklogs, indent=4))
|
print(json.dumps(week_worklogs, indent=4))
|
||||||
|
print("Days:")
|
||||||
|
print(days)
|
||||||
print(f"Omnimat string:")
|
print(f"Omnimat string:")
|
||||||
print(omnimat_string)
|
print(omnimat_string)
|
||||||
|
if days_second_part:
|
||||||
|
if VERBOSE:
|
||||||
|
print(f"Worklogs for the weeks 2nd part:")
|
||||||
|
print(json.dumps(worklogs_second_part, indent=4))
|
||||||
|
print("Days:")
|
||||||
|
print(days_second_part)
|
||||||
|
print(f"Omnimat string:")
|
||||||
|
print(omnimat_string)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user