Browse Source

python 2 and 3 compatible now

MalcolmMielle 5 years ago
parent
commit
543ebfbb89
2 changed files with 28 additions and 17 deletions
  1. 17
    9
      emails_sms_free.py
  2. 11
    8
      test.py

+ 17
- 9
emails_sms_free.py View File

@@ -1,14 +1,22 @@
1
-#!/usr/bin/env python3
1
+#!/usr/bin/env python
2 2
 # -*- coding:utf-8-*-
3 3
 
4
-import email
5
-import hashlib
6
-import imaplib
7
-import json
8
-import os.path
9
-import requests
10
-import sys
11
-import time
4
+from __future__ import print_function #print function python 2 and 3 compatible
5
+
6
+try:
7
+    #import urllib.request as urllib_request #for python 3
8
+	import email
9
+	import hashlib
10
+	import imaplib
11
+	import json
12
+	import os.path
13
+	import requests
14
+	import sys
15
+	import time
16
+except ImportError:
17
+	#import urllib2 as urllib_request # for python 2
18
+	import simplejson as json
19
+	print('Error importing lib as pyhton3, switching to python 2 libraries')
12 20
 
13 21
 msg_ids = {}
14 22
 

+ 11
- 8
test.py View File

@@ -1,12 +1,15 @@
1
-#!/usr/bin/env python3
1
+#!/usr/bin/env python
2
+
3
+from builtins import input #pour rendre input python2 and 3 compatible
2 4
 import emails_sms_free 
3 5
 
6
+
4 7
 if __name__ == '__main__':
5 8
 	url = "https://smsapi.free-mobile.fr/sendmsg"
6
-	user= raw_input("Please enter usr: ")
7
-	print "you entered", user
8
-	password= raw_input("Please enter password: ")
9
-	print "you entered", password
10
-	msg = raw_input("Please enter msg: ")
11
-	print "you entered", msg
12
-	send(url, user, password, msg, 1)
9
+	user= input("Please enter usr: ")
10
+	print("you entered" + str(user))
11
+	password= input("Please enter password: ")
12
+	print("you entered"+ str(password))
13
+	msg = input("Please enter msg: ")
14
+	print("you entered"+ str(msg))
15
+	end = emails_sms_free.send(url, user, password, msg)