Created
August 27, 2013 18:27
-
-
Save dpq/6357186 to your computer and use it in GitHub Desktop.
Backup SIM card contacts to a CSV file
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/python | |
import io | |
dev = "/dev/ttyUSB1" # Replace this if necessary | |
cmd,data = io.open(dev, "w"), io.open(dev, "r") | |
cmd.write(u"AT+CPBR=?\n") | |
min_id, max_id = -1, -1 | |
buffer = "" | |
while data.readable(): | |
b = data.readline() | |
if b == "OK\n": | |
break | |
if b[:6] == "+CPBR:": | |
min_id, max_id = map(lambda x: int(x), b[6:].split(",")[0].strip(" ()").split("-")) | |
from time import sleep | |
for i in range(min_id, max_id+1): | |
cmd.write(u"AT+CPBR=%d\n" % i) | |
while data.readable(): | |
b = data.readline() | |
if b == "OK\n": | |
break | |
elif b == "+CME ERROR: not found\n": | |
exit() | |
else: | |
if b[:6] == "+CPBR:": | |
buffer = b[:-1].split(",") | |
print buffer[3], ",", buffer[1] | |
sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment