Created
August 20, 2022 19:15
-
-
Save eagleEggs/81b12ee481680cdf9d22170aaf3eb204 to your computer and use it in GitHub Desktop.
TESTRAIL DJANGO REST FUNCTION PULL WITH TIMEFRAMES (VIEWS.py)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def puller(request): | |
action = request.GET.get('action', -1) | |
case = request.GET.get('case', -1) | |
timestamperbefore = request.GET.get('before', -1) | |
timestamperafter = request.GET.get('after', -1) | |
print(timestamperbefore) | |
print(timestamperafter) | |
tr_endpoint = "https://" | |
client = tr.APIClient(tr_endpoint) | |
client.user = "" | |
client.password = "" | |
# TIME FILTERS /////////////////////////////////////////////// | |
if timestamperbefore is -1 and timestamperafter is -1: | |
tr_json = client.send_get("{}/{}".format(action, case)) | |
return JsonResponse(tr_json, safe=False) | |
elif timestamperbefore is not -1 and timestamperafter is -1: | |
print("before") | |
dtime = datetime.datetime.strptime(str(timestamperbefore), "%Y,%m," | |
"%d") | |
dutime = time.mktime(dtime.timetuple()) | |
tr_json = client.send_get("{}/{}&created_before={}".format(action, | |
case, | |
int(dutime))) | |
return JsonResponse(tr_json, safe=False) | |
elif timestamperafter is not -1 and timestamperbefore is -1: | |
print("after") | |
dtime = datetime.datetime.strptime(str(timestamperafter), "%Y,%m," | |
"%d") | |
dutime = time.mktime(dtime.timetuple()) | |
tr_json = client.send_get("{}/{}&created_after={}".format(action, | |
case, | |
int(dutime))) | |
return JsonResponse(tr_json, safe=False) | |
elif timestamperbefore is not -1 and timestamperafter is not -1: | |
print("before and after") | |
dtimea = datetime.datetime.strptime(timestamperafter, "%Y,%m,%d") | |
dtimeb = datetime.datetime.strptime(timestamperbefore, "%Y,%m,%d") | |
dutimea = time.mktime(dtimea.timetuple()) | |
dutimeb = time.mktime(dtimeb.timetuple()) | |
tr_json = client.send_get("{}/{}&created_before={}&created_after={" | |
"}".format(action, | |
case, | |
int(dutimeb), | |
int(dutimea))) | |
return JsonResponse(tr_json, safe=False) | |
# TIME FILTERS ///////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment