Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app missingpeople #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added apps/missingpeople/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions apps/missingpeople/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import People
# Register your models here.

admin.site.register(People)
5 changes: 5 additions & 0 deletions apps/missingpeople/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class MissingpeopleConfig(AppConfig):
name = 'missingpeople'
22 changes: 22 additions & 0 deletions apps/missingpeople/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.1.5 on 2019-02-06 06:31

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='People',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('publicdate', models.CharField(max_length=999)),
('name', models.CharField(max_length=999)),
],
),
]
Empty file.
10 changes: 10 additions & 0 deletions apps/missingpeople/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models

# Create your models here.

class People(models.Model):
publicdate = models.CharField(max_length=999)
name = models.CharField(max_length=999)

def __str__(self):
return self.name
3 changes: 3 additions & 0 deletions apps/missingpeople/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions apps/missingpeople/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from apps.missingpeople.views import missingpeople, createcsv

app_name = 'missingpeople'

urlpatterns = [
path('missingpeople', missingpeople, name='missingpeople'),
path('createcsv', createcsv, name='createcsv'),
]
67 changes: 67 additions & 0 deletions apps/missingpeople/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import datetime
from bs4 import BeautifulSoup
import requests
from django.db.models import Model
import csv
from django.http import HttpResponse
from .models import People
from django.shortcuts import render

# Create your views here.

url = 'http://brumadinho.vale.com/listagem-pessoas-sem-contato.html'

#Esta view tem a funcao de ler os nomes das vitimas com beautifulsoap e inseri o nome e as informacoes da ultima atualizacao no banco de dados
def missingpeople(request):
page = requests.get(url)
if page.status_code == 200:
soup = BeautifulSoup(page.text, 'html.parser')
missinglist = soup.find_all('li')
lastupdate = soup.find_all('p')
try:
p = People.objects.latest('id')
except People.DoesNotExist:
p = None
if p == None:
i=0
for person in missinglist:
p = People(publicdate=lastupdate[3].text, name=person.text)
p.save()
i += 1
html = missinglist
return HttpResponse(html)
else:
if lastupdate[3].text == p.publicdate:
return HttpResponse(People.objects.all().values_list('name', flat=True))
else:
#inseri as pessoas uma a uma para fazer a contagem
i = 0
for person in missinglist:
p = People(publicdate=lastupdate[3].text, name=person.text)
p.save()
i += 1
html = missinglist
#print('Pessoas Desaparecidas: ', i)
return HttpResponse(html)
else:
return HttpResponse('<h1>Page was found</h1>')

def createcsv(request):
page = requests.get(url)
if page.status_code == 200:
soup = BeautifulSoup(page.text, 'html.parser')
missinglist = soup.find_all('li')
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
writer = csv.writer(response)

i = 0
for person in missinglist:
writer.writerow(person.text)
#p = People(publicdate=lastupdate[3].text, name=person.text)
#p.save()
i += 1

return HttpResponse(response)
else:
return HttpResponse('<h1>Page was found</h1>')
3 changes: 2 additions & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
# Application definition

INSTALLED_APPS = [
# 'django.contrib.admin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.api',
'apps.map',
'apps.missingpeople',
]

MIDDLEWARE = [
Expand Down
7 changes: 5 additions & 2 deletions core/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
# path('admin/', admin.site.urls),
path('admin/', admin.site.urls),
path('api/', include('apps.api.urls', namespace='api')),
path('', include('apps.map.urls', namespace='map'))
path('', include('apps.map.urls', namespace='map')),
path('', include('apps.missingpeople.urls', namespace='missingpeople'))

]