-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
58 lines (52 loc) · 1.95 KB
/
core.py
File metadata and controls
58 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import urllib
import simplejson
from subprocess import check_output
import time
import logging
def buscarFrase(frase):
query = urllib.urlencode({'q' : frase})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
if json:
if json['responseData']:
results = json['responseData']['results']
else:
return False
else:
return False
for i in results:
logging.info(" - Resultado: " + i['title'])
if i['title'].upper().find("LETRA") != -1 or i['title'].upper().find("LYRICS") != -1 or i['title'].upper().find("YOUTUBE") != -1 :
return i['title'] + " " + i['url']
return False
def publicarMensaje(mensaje):
logging.info(" - Ejecutamos twidge update \'" + resp + "\'")
return check_output(["twidge","update ","\'" + resp + "\'"])
logging.basicConfig(filename='myapp.log', level=logging.INFO)
while(3>2):
try:
salida = check_output(["twidge","lsrecent","-l","-s","-u"])
except:
logging.info("Error al obtener mensajes")
tweets = salida.split("\n");
for i in tweets:
if i != "":
(uuid,nick,_,texto,_,_) = i.split("\t")
logging.info("Buscar la frase: " + texto)
data = buscarFrase(texto)
if(data):
data = data.replace("<b>","").replace("</b>","").replace("!","")
logging.info(" - Encontrado en google:" + data)
resp = "@" + nick + " " + data
try:
x = publicarMensaje(resp)
logging.info(" - Salida del twidge:" + x)
except Exception as e:
logging.info("Error al twittear el mensaje ID:" + uuid )
logging.info(type(e))
logging.info(e)
else:
logging.info(" - No se encontró nada")