Skip to content

Instantly share code, notes, and snippets.



Created Feb 21, 2014
What would you like to do?
from subprocess import Popen, PIPE, STDOUT
from functools import partial
import re, datetime, random
ansi_escape = re.compile(r'\x1b[^m]*m')
p = Popen(['telegram'], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
print "starting..."
line = ""
title = ""
def wrt(m):
p.stdin.write("msg " + title.replace(" ", "_") + " " + m + "\n")
enquete = {}
while True:
if "changed title" in line:
title = line.split("changed title to ")[-1].strip()
title = ansi_escape.sub("", title)
elif line.startswith("Chat "):
title = ":".join(line.split("Chat ")[1].split(":")[:-1])
title = ansi_escape.sub("", title)
elif title in line and ">>>" in line:
msg = line.split(">>> ")[-1]
if msg.startswith("qotd"):
wrt("%s" % Popen(["fortune"], stdout=PIPE)"\n", " "))
elif msg.startswith("hora certa do pupi") or msg.startswith("pupi ta chegando?"):
wrt(random.choice(["atrasado ...", "chegando..", "quase la..", "hm...", "que horas sao?"]))
elif msg.startswith("hora certa"):
line = p.stdout.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.