Skip to content

Commit

Permalink
Merge pull request #5 from varendra007/varendra007/master/helper-utils
Browse files Browse the repository at this point in the history
Varendra007/master/helper utils
  • Loading branch information
anish1102 authored Feb 21, 2024
2 parents 7fc221f + 800b91b commit 185fa35
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from utils.colors import colors
import os
import datetime
import calendar


def fatal(message):
assert type(message) == str
print(colors.FAIL + message)
exit(0)


def logException(exp):
print(exp)
exit(0)


def getTimings(num_days):
today = datetime.datetime.now()
end_day = today - datetime.timedelta(days=1)
Expand All @@ -26,24 +28,24 @@ def getTimings(num_days):
if num_days <= days_in_current_month - days_left_in_current_month:
today = datetime.datetime.now()
endDay = today - datetime.timedelta(days=1)
startDay = endDay - datetime.timedelta(days=num_days-1)
startDay = endDay - datetime.timedelta(days=num_days - 1)
startMonth = startDay.strftime("%m")
startYear = startDay.strftime("%Y")
diff = (endDay.day - startDay.day) + 1
return {
"sw1": {
"sw1": {
"start_day": startDay.day,
"target_month": startMonth,
"end_day": endDay.day,
"day_diff": diff,
"target_month": startMonth,
"year": startYear,
"day_diff": diff
}
}
else:
today = datetime.datetime.now()
current_date = today - datetime.timedelta(days=1)
current_month = current_date.strftime("%m")
previous_date = current_date - datetime.timedelta(days=num_days-1)
previous_date = current_date - datetime.timedelta(days=num_days - 1)
previous_month = previous_date.strftime("%m")
previous_year = previous_date.strftime("%Y")
current_year = current_date.strftime("%Y")
Expand All @@ -57,19 +59,16 @@ def getTimings(num_days):
return {
"sw1": {
"start_day": prev_start_day,
"target_month": previous_month,
"end_day": prev_end_day,
"day_diff": prev_day_diff,
"target_month": previous_month,
"year": previous_year,
"day_diff": prev_day_diff
},
"sw2": {
"start_day": current_start_day,
"target_month": current_month,
"end_day": current_end_day,
"day_diff": current_day_diff,
"target_month": current_month,
"year": current_year,
"day_diff": current_day_diff
}
},
}



0 comments on commit 185fa35

Please sign in to comment.