{"id":273503,"date":"2016-02-03T13:17:03","date_gmt":"2016-02-03T10:17:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273503"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273503","title":{"rendered":"\u042d\u043a\u0441\u043f\u043e\u0440\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0432 Lingualeo.com"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e90\/1ca\/050\/e901ca0507db4e8cb28c33da72b06f3d.jpg\"\/><\/p>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u0442\u043e\u0440\u0438\u044f<\/h4>\n<p>  \u0414\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0441\u043b\u043e\u0432 \u0432 <a href=\"http:\/\/lingualeo.com\/\">Lingualeo.com<\/a> \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438\u043b\u0438 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u043e\u0432:<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/li>\n<\/ul>\n<p>  \u041c\u0438\u043d\u0443\u0441\u044b \u044d\u0442\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443. \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0437\u0430 \u0440\u0430\u0437.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0414\u043e\u043b\u0436\u043d\u043e \u0436\u0435 \u0431\u044b\u0442\u044c API?<\/h4>\n<p>  \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e api \u043d\u0430\u0439\u0442\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u041d\u041e! \u0415\u0441\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u0430 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0439\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 api \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<br \/>  \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 Google Chrome \u0438 \u0442\u043e\u043f\u0430\u0435\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u0412\u043d\u0438\u0437\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u043b\u044f Chrome. \u0411\u0440\u0430\u0443\u0437\u0435\u0440 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043f\u043a\u0443 Extensions (\u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 OS). \u0412\u043d\u0443\u0442\u0440\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043f\u043e\u043a \u0441 \u0445\u0435\u0448\u0430\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043f\u043e \u0434\u0430\u0442\u0435. \u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0444\u0430\u0439\u043b config.js \u2014 \u0432 \u043d\u0435\u043c \u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u0443\u0442\u0438 \u043a API \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0438 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<ul>\n<li>\/api\/login<\/li>\n<li>\/gettranslates<\/li>\n<li>\/addword<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041d\u0430 \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c?<\/h4>\n<p>  \u0412\u044b\u0431\u0440\u0430\u043b python, \u0442.\u043a. \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e OS. \u041c\u043e\u0434\u0443\u043b\u0438 \u0431\u0435\u0440\u0435\u043c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 api. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">service.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import urllib import urllib2 import json from cookielib import CookieJar   class Lingualeo:     def __init__(self, email, password):         self.email = email         self.password = password         self.cj = CookieJar()      def auth(self):         url = &quot;http:\/\/api.lingualeo.com\/api\/login&quot;         values = {             &quot;email&quot;: self.email,             &quot;password&quot;: self.password         }          return self.get_content(url, values)      def add_word(self, word, tword, context):         url = &quot;http:\/\/api.lingualeo.com\/addword&quot;         values = {             &quot;word&quot;: word,             &quot;tword&quot;: tword,             &quot;context&quot;: context,         }         self.get_content(url, values)      def get_translates(self, word):         url = &quot;http:\/\/api.lingualeo.com\/gettranslates?word=&quot; + urllib.quote_plus(word)          try:             result = self.get_content(url, {})             translate = result[&quot;translate&quot;][0]             return {                 &quot;is_exist&quot;: translate[&quot;is_user&quot;],                 &quot;word&quot;: word,                 &quot;tword&quot;: translate[&quot;value&quot;].encode(&quot;utf-8&quot;)             }         except Exception as e:             return e.message      def get_content(self, url, values):         data = urllib.urlencode(values)          opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))         req = opener.open(url, data)          return json.loads(req.read()) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435. \u041d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0440\u0435\u0448\u0438\u043b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f Kindle, \u0442.\u043a. \u043f\u0435\u0440\u0435\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u043d\u0435\u0433\u043e \u0442\u043e\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">handler.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">class Word:     text = '';     context = '';      def __init__(self, text):         self.text = text  class Base(object):     data = []      def __init__(self, source):         self.source = source      def get(self):         return self.data      def read(self):         raise NotImplementedError('Not implemented yet')   class Kindle(Base):     def read(self):         conn = sqlite3.connect(self.source)         sql = 'select word, usage from words LEFT JOIN LOOKUPS ON words.id = LOOKUPS.word_key where words.lang=&quot;en&quot; GROUP BY word ORDER BY word;'         for row in conn.execute(sql):             if isinstance(row[0], unicode):                 word = Word(row[0])                 if isinstance(row[1], unicode):                     word.context = row[1]                 self.data.append(word)         conn.close()   class Text(Base):     def read(self):         f = open(self.source)         for word in f.readlines():             self.data.append(Word(word))         f.close() <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430\/\u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0441\u043b\u043e\u0432:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">export.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import handler import config import service import sys  email = config.auth.get('email') password = config.auth.get('password')  export_type = sys.argv[1]  if export_type == 'text':     word_handler = handler.Text(config.sources.get('text')) elif export_type == 'kindle':     word_handler = handler.Kindle(config.sources.get('kindle')) else:     raise Exception('unsupported type')  word_handler.read()  lingualeo = service.Lingualeo(email, password) lingualeo.auth()  for word_dto in word_handler.get():     word = word_dto.text.lower().encode('utf-8')     translate = lingualeo.get_translates(word)      if translate[&quot;is_exist&quot;]:         print &quot;Already exists: &quot; + word.strip()     else:         context = word_dto.context.encode('utf-8')         lingualeo.add_word(word, translate[&quot;tword&quot;], context)         print &quot;Add word: &quot; + word.strip() <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h4>\n<p>  \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u0434 \u0441 github. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b config.py \u0438\u0437 config.py.dist. \u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u043c\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u0441 kindle \u0434\u043e sqlite \u0431\u0430\u0437\u044b \u0432\u043d\u0443\u0442\u0440\u0438 kindle.<\/p>\n<pre><code class=\"bash\">python export.py text #\u0414\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 python export.py kindle #\u0414\u043b\u044f kindle <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/h4>\n<p>  GitHub: <a href=\"https:\/\/github.com\/relaxart\/lingualeo.export\">lingualeo.export<\/a>.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/276495\/\"> https:\/\/habrahabr.ru\/post\/276495\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e90\/1ca\/050\/e901ca0507db4e8cb28c33da72b06f3d.jpg\"\/><\/p>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u0442\u043e\u0440\u0438\u044f<\/h4>\n<p>  \u0414\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0441\u043b\u043e\u0432 \u0432 <a href=\"http:\/\/lingualeo.com\/\">Lingualeo.com<\/a> \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0438\u043b\u0438 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u043e\u0432:<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/li>\n<\/ul>\n<p>  \u041c\u0438\u043d\u0443\u0441\u044b \u044d\u0442\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443. \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0437\u0430 \u0440\u0430\u0437.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-273503","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273503"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273503\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}