Browse Source

Merge pull request #1 from MalcolmMielle/master

python 2 et 3 compatible
Phyks (Lucas Verney) 5 years ago
parent
commit
5391d8d1dd
4 changed files with 31 additions and 3 deletions
  1. 2
    0
      README.md
  2. 0
    0
      __init__.py
  3. 14
    3
      emails_sms_free.py
  4. 15
    0
      test.py

+ 2
- 0
README.md View File

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

+ 0
- 0
__init__.py View File


+ 14
- 3
emails_sms_free.py View File

@@ -1,14 +1,25 @@
1
-#!/usr/bin/env python3
1
+#!/usr/bin/env python
2
+# -*- coding:utf-8-*-
3
+
4
+from __future__ import print_function #print function python 2 and 3 compatible
2 5
 
3 6
 import email
4 7
 import hashlib
5 8
 import imaplib
6
-import json
7 9
 import os.path
8 10
 import requests
9 11
 import sys
10 12
 import time
11 13
 
14
+#This is used to import library depending on the python version used.
15
+try:
16
+	#for python 3
17
+	import json
18
+except ImportError:
19
+	# for python 2
20
+	import simplejson as json
21
+	print('Error importing lib as python3, switching to python 2 libraries')
22
+
12 23
 msg_ids = {}
13 24
 
14 25
 
@@ -53,7 +64,7 @@ def send(url, user, password, msg, i=0):
53 64
 
54 65
 def get_emails(imap_server, imap_user, imap_password, inbox, uid):
55 66
     global msg_ids
56
-
67
+    
57 68
     print('Connecting to '+imap_server+'… ', end='')
58 69
     conn = imaplib.IMAP4_SSL(imap_server)
59 70
     print('Connected')

+ 15
- 0
test.py View File

@@ -0,0 +1,15 @@
1
+#!/usr/bin/env python
2
+
3
+from builtins import input #pour rendre input python2 and 3 compatible
4
+import emails_sms_free 
5
+
6
+
7
+if __name__ == '__main__':
8
+	url = "https://smsapi.free-mobile.fr/sendmsg"
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)