Merge pull request #1 from MalcolmMielle/master

python 2 et 3 compatible
This commit is contained in:
Lucas Verney 2014-11-14 20:22:27 +01:00
commit 5391d8d1dd
4 changed files with 31 additions and 3 deletions

View File

@ -2,3 +2,5 @@ Emails_SMS_Free_Mobile_API
========================== ==========================
Receive your emails _via_ SMS with the Free Mobile API. Receive your emails _via_ SMS with the Free Mobile API.
Compatible python 2 and 3

0
__init__.py Normal file
View File

View File

@ -1,14 +1,25 @@
#!/usr/bin/env python3 #!/usr/bin/env python
# -*- coding:utf-8-*-
from __future__ import print_function #print function python 2 and 3 compatible
import email import email
import hashlib import hashlib
import imaplib import imaplib
import json
import os.path import os.path
import requests import requests
import sys import sys
import time import time
#This is used to import library depending on the python version used.
try:
#for python 3
import json
except ImportError:
# for python 2
import simplejson as json
print('Error importing lib as python3, switching to python 2 libraries')
msg_ids = {} msg_ids = {}
@ -53,7 +64,7 @@ def send(url, user, password, msg, i=0):
def get_emails(imap_server, imap_user, imap_password, inbox, uid): def get_emails(imap_server, imap_user, imap_password, inbox, uid):
global msg_ids global msg_ids
print('Connecting to '+imap_server+'', end='') print('Connecting to '+imap_server+'', end='')
conn = imaplib.IMAP4_SSL(imap_server) conn = imaplib.IMAP4_SSL(imap_server)
print('Connected') print('Connected')

15
test.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
from builtins import input #pour rendre input python2 and 3 compatible
import emails_sms_free
if __name__ == '__main__':
url = "https://smsapi.free-mobile.fr/sendmsg"
user= input("Please enter usr: ")
print("you entered" + str(user))
password= input("Please enter password: ")
print("you entered"+ str(password))
msg = input("Please enter msg: ")
print("you entered"+ str(msg))
end = emails_sms_free.send(url, user, password, msg)