2022-02-05 21:35:04 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
import requests
|
|
|
|
from .models import DockerhubCrawler
|
2022-02-06 12:21:55 +00:00
|
|
|
# from django.db import models (Tried doesn't work:Sami)
|
|
|
|
import datetime
|
|
|
|
from datetime import timedelta
|
2022-02-05 21:35:04 +00:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
def HomePage(request):
|
|
|
|
return render(request, 'home.html', status=200)
|
|
|
|
|
|
|
|
|
|
|
|
def DockerPage(request):
|
2022-02-06 12:21:55 +00:00
|
|
|
#datatimeobjlast_pushedtemp = models.DateTimeField()
|
|
|
|
#datetimeobjtag_last_pushed = models.DateTimeField()
|
|
|
|
datatimeobjlast_pushedtemp = datetime.datetime.now()
|
|
|
|
datetimeobjtag_last_pushed = datetime.datetime.now()
|
2022-02-05 21:35:04 +00:00
|
|
|
count = 0
|
|
|
|
for dhubobj in DockerhubCrawler.objects.all():
|
|
|
|
resp = requests.get(url=dhubobj.api_url)
|
|
|
|
data = resp.json()
|
2022-02-06 12:21:55 +00:00
|
|
|
string_obj = ''
|
2022-02-05 21:35:04 +00:00
|
|
|
|
2022-02-06 12:21:55 +00:00
|
|
|
for chunk in data['results']: # looping through the data if updated in greater than prev date time save it
|
|
|
|
|
|
|
|
#print(chunk)
|
|
|
|
if count == 0: # first iteration lets just assign both object values
|
|
|
|
splits = ((chunk['tag_last_pushed'].split(":")))
|
|
|
|
#print(splits)
|
|
|
|
datatimeobjlast_pushedtemp = datetime.datetime(int(splits[0][:4]), int(splits[0][5:7])
|
|
|
|
,int(splits[0][8:10]), int(splits[0][11:]), int(splits[1][0:3]),
|
|
|
|
int(splits[2][0:2]), int(splits[2][3:len(splits[2])-1]))
|
|
|
|
datetimeobjtag_last_pushed = datetime.datetime(int(splits[0][:4]), int(splits[0][5:7])
|
|
|
|
,int(splits[0][8:10]), int(splits[0][11:]), int(splits[1][0:3]),
|
|
|
|
int(splits[2][0:2]), int(splits[2][3:len(splits[2])-1]))
|
|
|
|
string_obj = chunk['tag_last_pushed']
|
|
|
|
else:
|
|
|
|
splits = ((chunk['tag_last_pushed'].split(":")))
|
|
|
|
#print(splits)
|
|
|
|
#print(splits[0][:4], splits[0][5:7], splits[0][8:10],splits[0][11:] ,splits[1][0:3] , splits[2][0:2], splits[2][3:len(splits[2])-1])
|
2022-02-05 21:35:04 +00:00
|
|
|
|
2022-02-06 12:21:55 +00:00
|
|
|
datatimeobjlast_pushedtemp = splits = ((chunk['tag_last_pushed'].split(":")))
|
|
|
|
datatimeobjlast_pushedtemp = datetime.datetime(int(splits[0][:4]), int(splits[0][5:7])
|
|
|
|
,int(splits[0][8:10]), int(splits[0][11:]), int(splits[1][0:3]),
|
|
|
|
int(splits[2][0:2]), int(splits[2][3:len(splits[2])-1]))
|
|
|
|
if datatimeobjlast_pushedtemp > datetimeobjtag_last_pushed:
|
|
|
|
datetimeobjtag_last_pushed = datatimeobjlast_pushedtemp
|
|
|
|
string_obj = chunk['tag_last_pushed']
|
2022-02-05 21:35:04 +00:00
|
|
|
|
2022-02-06 12:21:55 +00:00
|
|
|
|
|
|
|
count = count + 1
|
|
|
|
|
|
|
|
# end for here, string_obj should have latest pushed date by now
|
2022-02-05 21:35:04 +00:00
|
|
|
|
2022-02-06 12:21:55 +00:00
|
|
|
splits = (string_obj.split(":"))
|
|
|
|
dhubobj.last_pushed = datetimeobjtag_last_pushed
|
|
|
|
# here we will notify and send the email
|
|
|
|
dhubobj.save()
|
2022-02-05 21:35:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
allobjs = DockerhubCrawler.objects.all()
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'docker.html', context={'dockerhubobjs': allobjs})
|