crawlerApp/dockerhubCrawler/views.py

46 lines
1.6 KiB
Python
Raw Normal View History

2022-02-05 21:35:04 +00:00
from django.shortcuts import render
import requests
from .models import DockerhubCrawler
from django.db import models
# Create your views here.
def HomePage(request):
return render(request, 'home.html', status=200)
def DockerPage(request):
datatimeobjlast_updatetemp = models.DateTimeField()
datetimeobjlast_updated = models.DateTimeField()
count = 0
for dhubobj in DockerhubCrawler.objects.all():
resp = requests.get(url=dhubobj.api_url)
data = resp.json()
for chunk in data['results']: # looping through the data if updated in greater than prev date time save it
if count == 0:
datatimeobjlast_updatetemp = models.DateTimeField(chunk['last_updated'])
datetimeobjlast_updated = models.DateTimeField(chunk['last_updated'])
else:
datatimeobjlast_updatetemp = models.DateTimeField(chunk['last_updated'])
if datatimeobjlast_updatetemp > datetimeobjlast_updated:
datetimeobjlast_updated = datatimeobjlast_updatetemp
count = count + 1
if dhubobj.last_updated == None:
# send eemail guys
dhubobj.last_updated = (datetimeobjlast_updated)
dhubobj.save()
if dhubobj.last_updated < datetimeobjlast_updated:
#send email here for now
dhubobj.last_updated = datetimeobjlast_updated
dhubobj.save()
allobjs = DockerhubCrawler.objects.all()
return render(request, 'docker.html', context={'dockerhubobjs': allobjs})