Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
adriacarrasquilla committed Oct 6, 2019
2 parents b8baff2 + fe037d4 commit 3b5ee0d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 10 deletions.
31 changes: 28 additions & 3 deletions FiltroPalabrasv2.0.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#!C:/Users/sergi/AppData/Local/Programs/Python/Python37-32/python.exe

import csv
import sys
import linkDownload as ld
import cgi

def csv2Dict(fichero):
with open(fichero) as f:
Expand All @@ -19,6 +19,7 @@ def CalculaScore():
datosForm = cgi.FieldStorage()

if datosForm:
<<<<<<< HEAD
url = datosForm["url"].value
arrayUrl = (url.split("//"))
if len(arrayUrl) == 2:
Expand All @@ -41,4 +42,28 @@ def CalculaScore():
return busqueda


print(CalculaScore())
print(CalculaScore())
=======
url = datosForm["url"].value
arrayUrl = (url.split("//"))
if len(arrayUrl) == 2:
url = arrayUrl[1]
else:
return 'Error url'

tema = datosForm["tema"].value

DicOdio = csv2Dict(tema+".csv") #'/Dicts/'+'
busqueda = ld.readLinks(url, tema)
ArrInter=[]
for url in busqueda["LINKS"]:
ArrInter = list(DicOdio.keys() & busqueda["LINKS"][url]["palabras"].keys())
for palabraClave in ArrInter:
if palabraClave in busqueda["LINKS"][url]["palabras"].keys():
busqueda["LINKS"][url]["puntuacion"] += busqueda["LINKS"][url]["palabras"][palabraClave]
return busqueda
else:
return "Input error"

print(CalculaScore())
>>>>>>> master
6 changes: 6 additions & 0 deletions linkDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ def readLinks(url, tema):
}

for link in arrayUrls[:-1]:
<<<<<<< HEAD
print("reading link: "+ link)
dicPalabrasLink = urlToList(link, url)
busqueda["LINKS"][link]=dicPalabrasLink #añadimos entrada de url: palabras.
=======
#print("reading link: "+ link)
dicPalabrasLink = urlToList(link, url)
busqueda["LINKS"][link]=dicPalabrasLink[link] #añadimos entrada de url: palabras.
>>>>>>> master

print(busqueda)
return busqueda
Expand Down
30 changes: 30 additions & 0 deletions obtenerListadoDominios.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
print("Content-Type: text/html\n")
import mysql.connector
import json

MAXIMO_DOMINIOS_A_LISTAR = 4

mydb = mysql.connector.connect(
host="localhost",
user="terrassahash",
passwd="HOMzOnzFaoBqvSk7",
db="terrassahash",
port=3306
)

def obtenerListadoDominios( maximoLineas):
"Obtenemos los ultimos analisis realizados en nuestra bd"
mycursor = mydb.cursor()
mycursor.execute("SELECT nombreDominio FROM dominio ORDER BY fecha DESC LIMIT " + str(maximoLineas))

resultado = []
for item in mycursor:
resultado.append(item);
return resultado

resultado = {}

resultado["respuesta"] = obtenerListadoDominios(MAXIMO_DOMINIOS_A_LISTAR)

print(json.dumps(resultado))
5 changes: 2 additions & 3 deletions racismo.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
negro,fuego,tiroteo,blanco,tirar,asesinato,amarillo,golpe,suicidio,gitano,dispara,paliza,bandas,puto,nazi,agresor,mono,esclavo,certificado,denuncia,lotería,barcelona
1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,2,1,1,1

negro, negra, mercado, odio, puto, putos, puta, putas, moros, cago, gilipollas, manteros, chupar, cojones, invasor, terrorista, muerte, muera, sangre, panchi, asqueroso, sudaca, raza, matarlos, Franco, matar, reviento, agrede, meca, machete, chabola, negrito, hijo, ilegal, indigente, inferior, peste, zorra, perra, cabrón, immigrante, pobre, sucio, orco, sobras, mueran, negrita, hija ,moro, culo
2,2,1,1,3,3,3,3,3,1,2,1,2,2,3,3,3,3,3,1,1,1,2,3,3,3,1,1,2,3,1,1,3,2,2,1,2,3,3,3,2,2,1,1,1,2,3,2,2,4
21 changes: 17 additions & 4 deletions web/assets/js/ConsultasBBDD.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
function getAjax(url,success){
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xhr.open('GET', url);
function getAjax() {
$.ajax({
url: "../../obtenerListadoDominios.py",
type: "GET",
success: function (response) {
alert(response);
var obj = JSON.parse(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
}

}


getAjax();
2 changes: 2 additions & 0 deletions web/assets/js/analizador.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function iniciarProceso(dominio, tematica) {
$.ajax({
url: "../FiltroPalabrasv2.0.py",
type: "POST",
timeout: 60000,
async: true,
data: {"url": dominio, "tema": tematica},
success: function (response) {
alert(response)
Expand Down
1 change: 1 addition & 0 deletions web/estadisticas.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ <h3>Sobre nosotros</h3>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/analizador.js"></script>
<script src="assets/js/ConsultasBBDD.js"></script>
</body>

</html>

0 comments on commit 3b5ee0d

Please sign in to comment.