57 lines
No EOL
1.8 KiB
Python
57 lines
No EOL
1.8 KiB
Python
from django.shortcuts import render
|
|
import requests
|
|
from .models import GithubCrawler
|
|
# Create your views here.
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
import datetime
|
|
|
|
def month_converter(month):
|
|
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
return months.index(month) + 1
|
|
|
|
|
|
def GithubPage(request):
|
|
|
|
for githubobj in GithubCrawler.objects.all():
|
|
|
|
URL = githubobj.api_url
|
|
page = requests.get(URL)
|
|
temp = ''
|
|
Soup = BeautifulSoup(page.text, 'lxml')
|
|
heading_tags = ["h2"]
|
|
for tags in Soup.find_all(heading_tags):
|
|
# print(tags)
|
|
temp = tags.text.strip()
|
|
break # first one is latest no need to loop through all of them
|
|
|
|
temp = temp[10:]
|
|
temp = temp.replace(",", "")
|
|
temp = temp.split(' ')
|
|
#print(temp)
|
|
last_pushed_thing = datetime.datetime(int(temp[3]), int(month_converter(temp[1])), int(temp[2])) # y-m-d
|
|
|
|
for div in Soup.findAll('div', attrs={'class':'issue-link js-issue-link'}):
|
|
print(div.find('a')['href'])
|
|
|
|
# finding commit number here and saving in db
|
|
|
|
el = Soup.find(class_='issue-link js-issue-link', href=True)
|
|
temp_result = (el['href'])
|
|
|
|
temp_result = temp_result.split('/')
|
|
last_pushed_number_thing = int(temp_result[len(temp_result)-1])
|
|
|
|
if githubobj.last_pushed_number:
|
|
if githubobj.last_pushed_number < last_pushed_number_thing:
|
|
print("send email and notify here")
|
|
|
|
githubobj.last_pushed_number = last_pushed_number_thing
|
|
githubobj.last_pushed = last_pushed_thing
|
|
|
|
githubobj.save()
|
|
|
|
allobjs = GithubCrawler.objects.all()
|
|
|
|
|
|
return render(request, 'github.html', context={'githubobjs': allobjs}) |