Skip to content

Commit ba2918f

Browse files
author
Emil Tullstedt
committed
Update to v0.4.6
1 parent 863a9a4 commit ba2918f

File tree

6 files changed

+32
-88
lines changed

6 files changed

+32
-88
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [0.4.6] - 2016-10-06
4+
### Added
5+
- Set explicit length limit for outgoing SMS
6+
### Removed
7+
- Outgoing call feature
8+
- List numbers feature
9+
310
## [0.4.4] - 2016-07-26
411
### Fixed
512
- Added requests as a requirement for elkme

elkme/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# see main.py for the main entry-point
44
#
55

6-
__version__ = '0.4.5'
7-
__release_date__ = '2016-07-26'
6+
__version__ = '0.4.6'
7+
__release_date__ = '2016-10-06'

elkme/config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ def default_config_location(Filename="elkme"):
3333
# That's ok, since XP is no longer supported by MSFT
3434
location = os.environ["LOCALAPPDATA"] + os.sep + Filename + ".ini"
3535

36-
# Migration if textme-conffile exists but not elkme
37-
if Filename == "elkme" and not os.path.isfile(location):
38-
oldconf = default_config_location("textme")
39-
if os.path.isfile(oldconf):
40-
os.rename(oldconf, location)
4136
return location
4237

4338

elkme/elks.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def format_sms_payload(self, message, to, sender='elkme', options=[]):
6565
'to': to,
6666
'message': message
6767
}
68-
68+
6969
for option in options:
7070
if option not in ['dontlog', 'dryrun', 'flash']:
7171
raise Exception('Option %s not supported' % option)
@@ -82,29 +82,3 @@ def send_sms(self, message, to, sender='elkme', options=[]):
8282
options=options)
8383
return self.query_api(sms)
8484

85-
def format_call_payload(self, payload, to, sender):
86-
voice_start = parse_payload(payload)
87-
88-
call = {
89-
'from': sender,
90-
'to': to,
91-
'voice_start': voice_start
92-
}
93-
return call
94-
95-
def make_call(self, payload, to, sender):
96-
""" Make a call connection to the 46elks API.
97-
Will be deprecated and replaced. """
98-
call = self.format_call_payload(payload, to, sender)
99-
return self.query_api(call, 'Calls')
100-
101-
def list_numbers(self, all = False):
102-
""" List numbers belonging to the current user.
103-
Will be deprecated and replaced. """
104-
response = self.query_api(endpoint='Numbers')
105-
numbers = json.loads(response)['data']
106-
if not all:
107-
numbers = filter(lambda num: num['active'] == 'yes', numbers)
108-
numbers = map(lambda num: num['number'], numbers)
109-
return list(numbers)
110-

elkme/helpers.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

elkme/main.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def main():
8181
"""Executed on run"""
8282

8383
try:
84-
input = raw_input
84+
io_in = raw_input
8585
except NameError:
86-
pass
86+
io_in = input
8787

8888
args = parse_args()
8989
if args.version:
@@ -114,16 +114,16 @@ def main():
114114
conf['password'] = args.password
115115

116116
message = None
117-
if args.message and not args.file:
117+
if args.message and not args.file: # Message in argument
118118
message = args.message
119-
elif args.file:
119+
elif args.file: # Read file support
120120
with open(args.file, 'r') as openfile:
121121
message = openfile.read()
122-
elif not sys.stdin.isatty():
122+
elif not sys.stdin.isatty(): # Pipe support
123123
message = ''
124124
try:
125125
while True:
126-
message += input()
126+
message += io_in()
127127
message += '\n'
128128
except EOFError:
129129
pass
@@ -145,14 +145,6 @@ def main():
145145
except KeyError:
146146
invalid_conf = True
147147

148-
if args.numbers:
149-
if not message:
150-
message = ''
151-
numbers = elks_conn.list_numbers(all = 'all' in message)
152-
for i, number in enumerate(numbers):
153-
print("(%s) %s" % (i, number))
154-
exit(0)
155-
156148
if not message:
157149
print(USAGE, file=sys.stderr)
158150
exit(-1)
@@ -162,20 +154,10 @@ def main():
162154

163155
if invalid_conf:
164156
print(USAGE, file=sys.stderr)
165-
print("\n\nYour configuration is invalid", file=sys.stderr)
157+
print("\n\nInvalid configuration", file=sys.stderr)
166158
exit(-1)
167159

168-
if args.call:
169-
response = elks_conn.make_call(message,
170-
conf.get('to', None),
171-
conf.get('from', None))
172-
if 'debug' in conf:
173-
print(response)
174-
elif 'verbose' in conf:
175-
retval = json.loads(response)
176-
print('Made connection to ' + conf['to'])
177-
else:
178-
send_sms(elks_conn, conf, message)
160+
send_sms(elks_conn, conf, message, length=args.length)
179161

180162
def parse_args():
181163
"""Parse the arguments to the application"""
@@ -207,20 +189,26 @@ def parse_args():
207189
action='count', help="""
208190
Generates a configuration file from the commandline
209191
options and exits.""")
192+
parser.add_argument('-l', '--length', metavar='length',
193+
action='store', type=int, default=160,
194+
help='Maximum length of the message')
210195
parser.add_argument('-c', '--config', dest='configfile',
211196
help="""Location of the custom configuration file""")
212-
parser.add_argument('--call', '--dial', action='store_true', default=False,
213-
help="""Make a call [TO BE DEPRECATED]""")
214-
parser.add_argument('--numbers', action='store_true',
215-
help="Show my numbers [TO BE DEPRECATED]")
216197
return parser.parse_args()
217198

218-
def send_sms(conn, conf, message):
199+
def send_sms(conn, conf, message, length=160):
219200
sender = conf.get('from', 'elkme')
220201
to = conf.get('to', None)
221202

203+
if length > 1530 or length < 0:
204+
print('Length must be larger than 0 and smaller than 1530')
205+
return
206+
207+
if not isinstance(message, str):
208+
message = " ".join(message)
209+
222210
try:
223-
response = conn.send_sms(message[:159], to, sender)
211+
response = conn.send_sms(message[:length], to, sender)
224212
except HTTPError as e:
225213
print(e)
226214
return
@@ -230,10 +218,10 @@ def send_sms(conn, conf, message):
230218
elif 'verbose' in conf:
231219
retval = json.loads(response)
232220

233-
if len(message) > 160:
221+
if len(message) > length:
234222
print(message)
235223
print('----')
236-
print('Sent first 160 characters to ' + retval['to'])
224+
print('Sent first %s characters to %s' % (length, retval['to']))
237225
else:
238226
print('Sent "' + retval['message'] + '" to ' + retval['to'])
239227

0 commit comments

Comments
 (0)