Skip to content

Instantly share code, notes, and snippets.

@r00tw33d
Forked from fitorec/twitterGetReplies.py
Created December 22, 2009 12:31
Show Gist options
  • Save r00tw33d/261718 to your computer and use it in GitHub Desktop.
Save r00tw33d/261718 to your computer and use it in GitHub Desktop.
Corrigiendo algunos detalles
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Copyright GNU/GPL 3.0 Fitorec <chanerec@gmail.com>
# Modify by r00t_w33d
# twitterGetReplies.py
# ____ _ _ .--.
# | __ |(_) | | ___ ____ ___ ____ | o_o |
# | | _ | ||_ _|/ _ \ / __// _ \ / __/ | :_/ |
# | __ || | | || (_) || | | __/| (__ // \ \
# |_| |_| | | \___/ |_| \___/ \___( (| | )
# http://fitorec.wordpress.com /'\_ _/
# \___)=(___/
# Creado : 22.12.2009
#
# Descripcion:
# Ejemplo practico: Mostrando NUM replicas del twitter útil pa integrar al conky
# requiere: El modulo de twitter de python
# Instalación: apt-get install python-twitter python-twyt
#
# ============= Configuracion =================
USER = "user" # usuario
PASS = "pass" #password
NUM = 3 #numero de replies x mostrar <=20
#===============================================
import twitter, re
api = twitter.Api(username = USER , password = PASS)
replies = api.GetReplies()
max_length = 55
for i in range(NUM):
pre = "[@"+replies[i].user.screen_name+"]:# "
textoNU = pre + re.sub('\&lt\;', '<', replies[i].text) #chafea con acentos
texto = textoNU.encode("utf-8") #ya no chafea xD
pre = " "
ltex = len(texto)
if ltex > max_length:
ini = 0
lineas = (ltex/max_length) #nunca sera = 0 ya ke ltex > max_length
ltex = ltex + (lineas*len(pre))
lineas = (ltex/max_length) + 1
for j in range(lineas):
if j == 0:
fin = max_length
print texto[ini:fin]
ini = fin
else:
fin = ini + max_length - len(pre)
print pre + texto[ini:fin]
ini = fin
else:
print texto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment