-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
30 lines (25 loc) · 931 Bytes
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import json
from http.cookiejar import CookieJar
class Lingualeo:
def __init__(self, email, password):
self.email = email
self.password = password
self.cj = CookieJar()
def auth(self):
url = "http://api.lingualeo.com/api/login"
values = {
"email": self.email,
"password": self.password
}
return self.get_content(url, values)
def get_translates(self, word):
url = "http://api.lingualeo.com/gettranslates?word=" + urllib.parse.quote_plus(word)
return self.get_content(url, {})
def get_content(self, url, values):
data = urllib.parse.urlencode(values)
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cj))
req = opener.open(url, data.encode('utf-8'))
return json.loads(req.read().decode('utf-8'))