ich hab da ein saukomisches Problem:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: UTF8 -*-
import sys
import os
import getopt
import smsutils
import pickle
def usage():
print """
pyss [options]|recipients
[OPTIONS]
-v|--verbose verbose mode (not supported)
-h|--help shows this screen
-s|--setup setup Pyss
-c|--change change Pyss setup
-g|--group manage groups
-p|--person manage person
[Example]
pyss --help Shows this screen
pyss Send short message
pyss -s pyss setup
"""
def send(data):
print "Recipients:"
recipients = raw_input()
recipient_list = recipients.split()
print "Message:"
message = raw_input()
sms = smsutils.processsms(data, message, recipient_list)
finalr = sms.getnumbers()
finalm = sms.tokenizemessage()
sms.sendsms(finalm, finalr)
print "Success!"
return recipient_list, message
def setup():
print "Doing setup"
print
person = {}
group = {}
setupdata = {}
if not os.path.exists("/home/william/.smssend"):
os.mkdir("~/.smssend", 0644)
out = 1
while out:
d = raw_input("""Input your sendsms setup directory. (default = ~/.smssend)""")
if d:
if os.path.exists(d):
out = 0
else:
print "Path does not exist. Shall I create:", d
print "Default = yes"
answer = raw_input()
if not answer or answer == "y" or answer == "yes":
os.mkdir(d, mode="0644")
out = 0
else:
pass
else:
d = "~/.smssend"
out = 0
setupdata.update({ "confighome" : d })
out = 1
while out:
pf = raw_input("Input your provider file. (default = orange.sms)")
ptpf = raw_input("Input path to your provider file. (default = ~/.smssend/)")
if not pf and not ptpf:
path = d + "/orange.sms"
if os.path.exists(path):
out = 0
print "Provider file set to:", path
else:
print "Error! There is no providerfile! You have to get one for pyss and sendsms to work!"
elif pf and not ptpf:
path = d + "/" + pf
if os.path.exists(path):
out = 0
print "Provider file set to:", path
else:
print "Error! There is no providerfile! You have to get one for pyss and sendsms to work!"
elif not pf and ptpf:
path = ptpf + "/orange.sms"
if os.path.exists(path):
out = 0
print "Provider file set to:", path
else:
print "Error! There is no providerfile! You have to get one for pyss and sendsms to work!"
else:
path = ptpf + "/" + pf
if os.path.exists(path):
out = 0
print "Provider file set to:", path
else:
print "Error! There is no providerfile! You have to get one for pyss and sendsms to work!"
setupdata.update({ "provider" : path })
out = 1
while out:
pb = raw_input("If you have a phonebook-file (*.pb) please input path:")
if pb and os.path.exists(pb):
setupdata.update({ "pb" : pb })
out = 0
elif pb and not os.path.exists(pb):
print "This file does not exist. Please retry or go on."
else:
out = 0
sig = raw_input("Please input a signature (default = no signature:")
if not sig:
setupdata.update({ "sig" : "" })
else:
print "Set", sig, "as your signature"
setupdata.update({ "sig" : sig })
if setupdata.has_key("pb"):
result = importpb(setupdata["pb"])
person.update(result)
del setupdata["pb"]
else:
pass
datafilepath = d + "/" + "pyssdata.pik"
datafile = open(datafilepath, "w")
completedata = (person, group, setupdata, [])
control = smsutils.manageaccount(completedata)
print "This are your settings:"
control.showentry(2)
q = raw_input("Is this correct? (default = yes)")
if not q or q == "yes" or q == "y":
pass
else:
changes(completedata)
pickle.dump(completedata, datafile)
datafile.close()
def importpb(path):
pb = open(path, "r")
line = pb.readline()
book = {}
while line:
couple = line.split(":")
print "Set number", couple[1], "to person", couple[0]
result = raw_input("Default = yes")
if not result or result == "y" or result == "yes":
book.update({ couple[0]:couple[1]})
else:
pass
line = pb.readline()
return book
def changes(data):
print "These are your settings.:"
control = smsutils.manageaccount(completedata)
control.showentry(2)
c = raw_input("Press [Enter] if they are okay or input the setting you want to change:")
if not c:
pass
else:
if data[2].has_key(c):
print "Enter new value for", c
new = raw_input()
data[2].changeentry(c, new)
else:
print "This setting does not exist!"
changes()
def managegroup(data):
print "These are your groups"
control = smsutils.manageaccount(data)
control.showentry(1)
c = raw_input("Press [Enter] if they are okay or input the group you want to change or input a new group name:")
if not c:
sys.exit()
else:
if data[1].has_key(c):
print "Enter new value for", c
new = raw_input()
data[1].changeentry(c, new)
else:
print "Creating new group", c
members = raw_input("Please input members of the group separated by a blank space:")
memberlist = members.split()
addentry(c, memberlist, 1)
managegroup(data)
def manageperson(data):
print "These are the persons in your phonebook:"
control = smsutils.manageaccount(data)
control.showentry(0)
c = raw_input("Press [Enter] if they are okay or input the person you want to change:")
if not c:
sys.exit()
else:
if data[0].has_key(c):
print "Enter new value for", c
new = raw_input()
data[0].changeentry(c, new)
else:
print "Creating new person", c
number = raw_input("Please input number of the person:")
addentry(c, number, 0)
manageperson(data)
def verbose():
print "Verbose mode not yet supported"
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "vhscgp", ["verbose", "help", "setup", "change", "group", "person"])
except getopt.GetoptError:
usage()
sys.exit(2)
if opts:
for o, a in opts:
if o in ("-v", "--verbose"):
verb = 1
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-s", "--setup"):
setup()
sys.exit()
elif o in ("-c", "--change"):
change()
sys.exit()
elif o in ("-g", "--group"):
managegroup()
sys.exit()
elif o in ("-p", "--person"):
manageperson()
sys.exit()
else:
print "Sending sms"
else:
try:
pass
Kann mir jemand sagen was das Problem sein könnte?