Created
February 21, 2014 18:01
-
-
Save bgola/9139600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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