From 0fe65f4b4da0495da04faeadcbd070e31085692d Mon Sep 17 00:00:00 2001 From: MalcolmMielle Date: Tue, 4 Nov 2014 12:58:50 +0100 Subject: [PATCH 1/5] Added utf8 for accent in print and a test file --- __init__.py | 0 emails_sms_free.py | 4 ++-- test.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 __init__.py create mode 100644 test.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/emails_sms_free.py b/emails_sms_free.py index 388cd37..acdbdf7 100755 --- a/emails_sms_free.py +++ b/emails_sms_free.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# -*- coding:utf-8-*- import email import hashlib @@ -53,8 +54,7 @@ def send(url, user, password, msg, i=0): def get_emails(imap_server, imap_user, imap_password, inbox, uid): global msg_ids - - print('Connecting to '+imap_server+'… ', end='') + print('Connecting to '+imap_server+'… ', end=' ') conn = imaplib.IMAP4_SSL(imap_server) print('Connected') to_send = [] diff --git a/test.py b/test.py new file mode 100644 index 0000000..233e1e8 --- /dev/null +++ b/test.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import emails_sms_free + +if __name__ == '__main__': + url = "https://smsapi.free-mobile.fr/sendmsg" + user= raw_input("Please enter usr: ") + print "you entered", user + password= raw_input("Please enter password: ") + print "you entered", password + msg = raw_input("Please enter msg: ") + print "you entered", msg + send(url, user, password, msg, 1) From 543ebfbb898205b2a824a050e822841ff9d1a656 Mon Sep 17 00:00:00 2001 From: MalcolmMielle Date: Tue, 4 Nov 2014 13:45:57 +0100 Subject: [PATCH 2/5] python 2 and 3 compatible now --- emails_sms_free.py | 26 +++++++++++++++++--------- test.py | 19 +++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/emails_sms_free.py b/emails_sms_free.py index acdbdf7..5457f95 100755 --- a/emails_sms_free.py +++ b/emails_sms_free.py @@ -1,14 +1,22 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding:utf-8-*- -import email -import hashlib -import imaplib -import json -import os.path -import requests -import sys -import time +from __future__ import print_function #print function python 2 and 3 compatible + +try: + #import urllib.request as urllib_request #for python 3 + import email + import hashlib + import imaplib + import json + import os.path + import requests + import sys + import time +except ImportError: + #import urllib2 as urllib_request # for python 2 + import simplejson as json + print('Error importing lib as pyhton3, switching to python 2 libraries') msg_ids = {} diff --git a/test.py b/test.py index 233e1e8..45bb98a 100644 --- a/test.py +++ b/test.py @@ -1,12 +1,15 @@ -#!/usr/bin/env python3 +#!/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= raw_input("Please enter usr: ") - print "you entered", user - password= raw_input("Please enter password: ") - print "you entered", password - msg = raw_input("Please enter msg: ") - print "you entered", msg - send(url, user, password, msg, 1) + 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) From e2c85047ce2aeca307b13582ca83c3a56446042c Mon Sep 17 00:00:00 2001 From: MalcolmMielle Date: Tue, 4 Nov 2014 13:49:09 +0100 Subject: [PATCH 3/5] corrected the try - import statement --- emails_sms_free.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/emails_sms_free.py b/emails_sms_free.py index 5457f95..fb34148 100755 --- a/emails_sms_free.py +++ b/emails_sms_free.py @@ -3,16 +3,18 @@ from __future__ import print_function #print function python 2 and 3 compatible +import email +import hashlib +import imaplib +import os.path +import requests +import sys +import time + +#This is used to import library depending on the python version used. try: - #import urllib.request as urllib_request #for python 3 - import email - import hashlib - import imaplib + #import urllib.request as urllib_request #for python 3 import json - import os.path - import requests - import sys - import time except ImportError: #import urllib2 as urllib_request # for python 2 import simplejson as json From 9fc7cca18211960942db28f1832450cb12e469e4 Mon Sep 17 00:00:00 2001 From: Malcolm Mielle Date: Tue, 4 Nov 2014 14:52:49 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ded5276..11c4a17 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ Emails_SMS_Free_Mobile_API ========================== Receive your emails _via_ SMS with the Free Mobile API. + +Compatible python 2 and 3 From 91a7334a65097960080a1f9a8cb80bdffd1f3e1b Mon Sep 17 00:00:00 2001 From: MalcolmMielle Date: Fri, 14 Nov 2014 15:56:45 +0100 Subject: [PATCH 5/5] Corrected things from the merge. --- emails_sms_free.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/emails_sms_free.py b/emails_sms_free.py index fb34148..30bbcfc 100755 --- a/emails_sms_free.py +++ b/emails_sms_free.py @@ -13,12 +13,12 @@ import time #This is used to import library depending on the python version used. try: - #import urllib.request as urllib_request #for python 3 + #for python 3 import json except ImportError: - #import urllib2 as urllib_request # for python 2 + # for python 2 import simplejson as json - print('Error importing lib as pyhton3, switching to python 2 libraries') + print('Error importing lib as python3, switching to python 2 libraries') msg_ids = {} @@ -64,7 +64,8 @@ def send(url, user, password, msg, i=0): def get_emails(imap_server, imap_user, imap_password, inbox, uid): global msg_ids - print('Connecting to '+imap_server+'… ', end=' ') + + print('Connecting to '+imap_server+'… ', end='') conn = imaplib.IMAP4_SSL(imap_server) print('Connected') to_send = []