Better exception handling

This commit is contained in:
Phyks 2014-08-03 11:58:38 +02:00
parent 97c270b3a5
commit 67151eba76
1 changed files with 4 additions and 5 deletions

View File

@ -20,10 +20,9 @@ def get_subject(subject_header):
return tmp[0].decode(tmp[1]) return tmp[0].decode(tmp[1])
def send(url, msg, i=0): def send(url, user, password, msg, i=0):
full_url = url.replace('{$msg}', msg)
try: try:
r = requests.get(full_url, verify=False) r = requests.get(url, params={'user': user, 'pass': password, 'msg': msg}, verify=False)
if r.status_code == 200: if r.status_code == 200:
return True return True
elif r.status_code == 400: elif r.status_code == 400:
@ -120,7 +119,7 @@ if __name__ == '__main__':
'inbox': 'INBOX'}] 'inbox': 'INBOX'}]
save_path = os.path.expanduser('~/.emails_sms_free.json') save_path = os.path.expanduser('~/.emails_sms_free.json')
debug = False debug = False
url = "https://smsapi.free-mobile.fr/sendmsg?user={$user}&pass={$pass}&msg={$msg}" url = "https://smsapi.free-mobile.fr/sendmsg"
user = 'IDENT' user = 'IDENT'
password = 'PASS' password = 'PASS'
# YOU SHOULD NOT HAVE TO EDIT BELOW # YOU SHOULD NOT HAVE TO EDIT BELOW
@ -149,7 +148,7 @@ if __name__ == '__main__':
msg = ('New email from '+data['from']+'\n' + msg = ('New email from '+data['from']+'\n' +
data['subject']+'\n' + data['subject']+'\n' +
str(data['content'][:700])+'...') str(data['content'][:700])+'...')
if send(url, msg): if send(url, user, password, msg):
print('Sent '+str(i)+'/'+str(len(to_send))) print('Sent '+str(i)+'/'+str(len(to_send)))
else: else:
msg_ids[data['server_uid']].remove(data['id']) msg_ids[data['server_uid']].remove(data['id'])