{"id":285413,"date":"2017-04-24T11:20:46","date_gmt":"2017-04-24T07:20:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285413"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285413","title":{"rendered":"\u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u0442\u043e\u0432 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 Trello"},"content":{"rendered":"<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0435\u0441\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0430 \u0432 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u043e \u043a\u0438\u043d\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043e\u043d\u0441\u044b \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438 \u0435\u0449\u0451 \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u043a\u0443 Trello, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u044b \u0438 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 API \u0447\u0442\u043e\u0431\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u0441\u0442\u044b \u0432 \u0433\u0440\u0443\u043f\u043f\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c04\/ce3\/77e\/c04ce377efa6425cbdfcafcf0d4a7d2b.jpeg\" alt=\"image\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043e\u0441\u043a\u0443 \u0432 Trello \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &quot;\u041a\u0438\u043d\u043e&quot;, \u0430 \u0432 \u043d\u0435\u0439 \u0434\u0432\u0430 \u043b\u0438\u0441\u0442\u0430 &quot;\u041d\u043e\u0432\u0438\u043d\u043a\u0438 \u043d\u0435\u0434\u0435\u043b\u0438&quot; \u0438 &quot;\u0421\u043a\u043e\u0440\u043e \u0432 \u043f\u0440\u043e\u043a\u0430\u0442\u0435&quot;. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0443\u0434\u0430 4 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438, 2 \u0441 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f, 1 \u043d\u0430 \u0437\u0430\u0432\u0442\u0440\u0430 \u0438 1 \u0431\u0435\u0437 \u0434\u0430\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Trello API \u0438 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 API \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">$ pip3 install py-trello $ pip3 install py-vkontakte<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"dostup-k-trello-api\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a Trello API<\/h4>\n<p>  <\/p>\n<p><em>KEY<\/em> \u0438 <em>TOKEN<\/em> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0443\u0442 <a href=\"https:\/\/trello.com\/app-key\">https:\/\/trello.com\/app-key<\/a><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import trello client = trello.TrelloClient(api_key=KEY, token=TOKEN) board = client.get_board(ID)  # \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 https:\/\/trello.com\/b\/nC8QJJoZ\/, \u0433\u0434\u0435 ID \u2014 nC8QJJoZ<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &quot;Due Date&quot; \u0432 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0435 Trello \u043c\u044b \u0437\u0430\u0434\u0430\u0451\u043c, \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0432 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def is_card_can_published(trello_card):     if not trello_card.due_date:         return False      now_unixtime = datetime.datetime.utcnow().replace(tzinfo=None).timestamp()     card_due_unixtime = trello_card.due_date.replace(tzinfo=None).timestamp()      delta = card_due_unixtime - now_unixtime     return True if delta &lt;= 0 else False  card_items = (card for card in board.open_cards() if is_card_can_published(card))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044f Trello.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/002\/631\/0ec\/0026310ec2a64c62b2a9e29777039e35.jpeg\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u041a \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0444\u0430\u0439\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0443 \u0444\u0430\u0439\u043b\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>get_attachment_in_card<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436 &quot;\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430&quot; \u0438 &quot;\u0431\u0430\u0439\u0442\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f&quot;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f, \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 \u0412\u041a.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import os import requests  def is_image_file(attachment_url):     _, file_extension = os.path.splitext(attachment_url)      if file_extension not in ('.jpg', '.gif', '.png'):         return False      return True  def download_attachment(attachment_url):     response = requests.get(attachment_url, stream=True)     return response.content  def get_attachment_in_card(card):     for attachment in card.get_attachments():         if not is_image_file(attachment.url):             continue          binary_content = download_attachment(attachment.url)         _, filename = os.path.split(attachment.url)         yield (filename, binary_content)<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"dostup-k-vkontakte-api\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 API<\/h4>\n<p>  <\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0451\u043c Standalone-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <a href=\"https:\/\/vk.com\/editapp?act=create\">https:\/\/vk.com\/editapp?act=create<\/a><\/li>\n<li>\u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f &quot;ID_\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f&quot; \u0438 &quot;\u0417\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439_\u043a\u043b\u044e\u0447&quot;<\/li>\n<\/ol>\n<p>  <\/p>\n<p><a href=\"https:\/\/vk.com\/dev\/authcode_flow_user\">https:\/\/vk.com\/dev\/authcode_flow_user<\/a><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; import vk &gt;&gt;&gt; vk.create_url_get_code(&quot;ID_\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435&quot;, 'https:\/\/oauth.vk.com\/blank.html', scope='wall, photos')  # \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f CODE &gt;&gt;&gt; vk.create_access_token(&quot;ID_\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435&quot;, &quot;\u0417\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439_\u043a\u043b\u044e\u0447&quot;, &quot;https:\/\/oauth.vk.com\/blank.html&quot;, &quot;CODE&quot;)  # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ACCESS_TOKEN<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0412\u041a \u0447\u0435\u0440\u0435\u0437 <code>py-vkontakte<\/code><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import vk vk.set_access_token(ACCESS_TOKEN) group = vk.get_group(ID)  # vk.com\/apiclub, \u0433\u0434\u0435 ID \u2014 apiclub \u0438\u043b\u0438 vk.com\/club1, \u0433\u0434\u0435 ID \u2014 1<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>&quot;get_attachment_in_card&quot;<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438 Trello. \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0412\u041a \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0432 \u0433\u0440\u0443\u043f\u043f\u0435. \u041f\u043e\u0441\u043b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u0442\u0430 \u0432 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435, &quot;due date&quot; \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from vk.photos import Photo  for card in card_items:     attachment_items = \\         {filename: binary_content for filename, binary_content in get_attachment_in_card(card)}     photo_items = Photo.upload_wall_photos_for_group(group.id, attachment_items.items())     group.wall_post(message=card.name + '\\n' + card.description, attachments=photo_items)     card.set_due_complete()<\/code><\/pre>\n<p>  <\/p>\n<p>\u2192 <a href=\"https:\/\/github.com\/sgaynetdinov\/postin-in-vk-from-trello\">GitHub<\/a><\/p>\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\/327216\/\"> https:\/\/habrahabr.ru\/post\/327216\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0435\u0441\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0430 \u0432 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 \u043e \u043a\u0438\u043d\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043e\u043d\u0441\u044b \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438 \u0435\u0449\u0451 \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u043a\u0443 Trello, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u044b \u0438 \u0412\u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0435 API \u0447\u0442\u043e\u0431\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u0441\u0442\u044b \u0432 \u0433\u0440\u0443\u043f\u043f\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c04\/ce3\/77e\/c04ce377efa6425cbdfcafcf0d4a7d2b.jpeg\" alt=\"image\"\/><\/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-285413","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285413","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=285413"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285413\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}