Created
December 25, 2008 20:15
-
-
Save quad/39946 to your computer and use it in GitHub Desktop.
Spam your friends with Christmas Greetings
This file contains 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/env python | |
# | |
# Spam your phonebook (Nokia) with Christmas cheer. | |
# | |
# Usage: merryspam.py vcards names | |
# | |
# How do I get the "vcards"? | |
# | |
# gnokii --getphonebook ME 1 end -v > ME.vcards | |
# gnokii --getphonebook SM 1 end -v > SM.vcards | |
# cat ME.vcards SM.vcards > vcards | |
# | |
# How do I get the "names"? | |
# | |
# grep "^FN:" vcards | cut -c 4- > names | |
# | |
# Then edit for the "names" you /actually/ want to receive cheer. | |
# | |
# (Careful, "names" will have \r\n style newlines.) | |
# | |
import subprocess | |
import sys | |
import time | |
import vobject | |
class SMSException(Exception): | |
pass | |
def send_text(pn, msg): | |
assert int(pn) | |
g = subprocess.Popen("/usr/bin/gnokii --sendsms %s" % pn, | |
stdin = subprocess.PIPE, | |
shell = True) | |
g.communicate(msg) | |
g.wait() | |
if g.returncode: | |
raise SMSException("Failed text to %s!" % pn) | |
if __name__ == '__main__': | |
fn_vcards, fn_names = sys.argv[1:] | |
in_vcards = file(fn_vcards) | |
vcards = vobject.readComponents(in_vcards) | |
in_names = file(fn_names) | |
names = [name.strip() for name in in_names.readlines()] | |
for v in vcards: | |
if v.fn.value in names: | |
while True: | |
try: | |
send_text(v.tel.value, "Merry Christmas!") | |
except SMSException: | |
print "Gimme a sec, the telephone company rate-limited us..." | |
time.sleep(30) | |
else: | |
break | |
print "OK %s" % v.fn.value | |
names.remove(v.fn.value) | |
print "No hit: %s" % names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment