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