Skip to content

Instantly share code, notes, and snippets.

@bgola
Created February 21, 2014 18:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgola/9139600 to your computer and use it in GitHub Desktop.
Save bgola/9139600 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
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)
p.stdout.read(255)
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).stdout.read().replace("\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"):
wrt(datetime.datetime.now().strftime("%H:%M:%S"))
line = p.stdout.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment