{"action":"created","comment":{"url":"https://api.github.com/repos/fidals/shopelectro/pulls/comments/65511909","id":65511909,"diff_hunk":"@@ -0,0 +1,244 @@\n+\"\"\"Import catalog management command.\"\"\"\n+\n+import os\n+import time\n+import typing\n+from ftplib import FTP\n+from functools import wraps\n+from xml.etree import ElementTree\n+\n+from django.db import transaction\n+from django.core.management import call_command\n+from django.core.management.base import BaseCommand\n+\n+from catalog.models import Category\n+from shopelectro.models import Product\n+\n+\n+result_message = str  # Type alias for returning result information\n+\n+\n+# TODO: Do we really need it?\n+CATEGORY_POSITIONS = {\n+    24: 1,\n+    22: 2,\n+    18: 3,\n+    17: 4,\n+    7: 5,\n+    137: 1,\n+    160: 2,\n+    157: 3,\n+    25: 4,\n+    155: 5,\n+    152: 6,\n+    26: 7,\n+    34: 8,\n+    35: 9,\n+    36: 10,\n+    27: 11,\n+    138: 1,\n+    41: 2,\n+    40: 3,\n+    39: 4,\n+    38: 5,\n+    37: 6,\n+    55: 1,\n+    54: 2,\n+    53: 3,\n+    52: 4,\n+    48: 5,\n+    153: 1,\n+    151: 2,\n+    170: 3,\n+    167: 4,\n+    169: 5,\n+    150: 6,\n+    145: 7,\n+    81: 8,\n+    74: 9,\n+    104: 10,\n+    111: 11,\n+    140: 12,\n+    63: 13,\n+    6: 1,\n+    2: 2,\n+    3: 3,\n+    4: 4,\n+    5: 5\n+}\n+\n+\n+def process(procedure_name: str) -> callable:\n+    \"\"\"Print information before starting procedure and after it's been finished.\"\"\"\n+    def inner(procedure: callable) -> callable:\n+        \"\"\"Decorator's factory.\"\"\"\n+        @wraps(procedure)\n+        def wrapper(*args: tuple, **kwargs: dict) -> None:\n+            \"\"\"Print result before function call and after it.\"\"\"\n+            print('{}...'.format(procedure_name))\n+            result = procedure(*args, **kwargs)\n+            print(result or 'Завершено: {}'.format(procedure_name))\n+        return wrapper\n+    return inner\n+\n+\n+@process('Загрузка информации в базу')\n+def delete_and_create(model_generator_mapping: list) -> result_message:\n+    \"\"\"Perform db transaction of removing current rows and creating new ones.\"\"\"\n+    def purge_table(model):\n+        \"\"\"Removes every row from Model's table.\"\"\"\n+        model.objects.all().delete()\n+\n+    def save_instances(collection):","path":"shopelectro/management/commands/catalog.py","position":92,"original_position":92,"commit_id":"a8e675185ef073d701eb34545ad0edc69257398f","original_commit_id":"a8e675185ef073d701eb34545ad0edc69257398f","user":{"login":"begor","id":10001148,"avatar_url":"https://avatars.githubusercontent.com/u/10001148?v=3","gravatar_id":"","url":"https://api.github.com/users/begor","html_url":"https://github.com/begor","followers_url":"https://api.github.com/users/begor/followers","following_url":"https://api.github.com/users/begor/following{/other_user}","gists_url":"https://api.github.com/users/begor/gists{/gist_id}","starred_url":"https://api.github.com/users/begor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begor/subscriptions","organizations_url":"https://api.github.com/users/begor/orgs","repos_url":"https://api.github.com/users/begor/repos","events_url":"https://api.github.com/users/begor/events{/privacy}","received_events_url":"https://api.github.com/users/begor/received_events","type":"User","site_admin":false},"body":"> чем смотреть на функцию, её коммент и вызов\r\n\r\nСмысл функции в том, что бы не смотреть на нее. \r\n`save_instances` сохраняет инстансы. Это все, что стоит о ней знать.\r\nЕсли приходится смотреть в тело функции, чтобы понять, что она делает - значит с функцией что-то не так.","created_at":"2016-06-02T09:46:50Z","updated_at":"2016-06-02T09:46:50Z","html_url":"https://github.com/fidals/shopelectro/pull/20#discussion_r65511909","pull_request_url":"https://api.github.com/repos/fidals/shopelectro/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/comments/65511909"},"html":{"href":"https://github.com/fidals/shopelectro/pull/20#discussion_r65511909"},"pull_request":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/fidals/shopelectro/pulls/20","id":72198114,"html_url":"https://github.com/fidals/shopelectro/pull/20","diff_url":"https://github.com/fidals/shopelectro/pull/20.diff","patch_url":"https://github.com/fidals/shopelectro/pull/20.patch","issue_url":"https://api.github.com/repos/fidals/shopelectro/issues/20","number":20,"state":"open","locked":false,"title":"Import command and Property model.","user":{"login":"begor","id":10001148,"avatar_url":"https://avatars.githubusercontent.com/u/10001148?v=3","gravatar_id":"","url":"https://api.github.com/users/begor","html_url":"https://github.com/begor","followers_url":"https://api.github.com/users/begor/followers","following_url":"https://api.github.com/users/begor/following{/other_user}","gists_url":"https://api.github.com/users/begor/gists{/gist_id}","starred_url":"https://api.github.com/users/begor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begor/subscriptions","organizations_url":"https://api.github.com/users/begor/orgs","repos_url":"https://api.github.com/users/begor/repos","events_url":"https://api.github.com/users/begor/events{/privacy}","received_events_url":"https://api.github.com/users/begor/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-01T15:08:14Z","updated_at":"2016-06-02T09:46:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebf6e98b5e30053d682a3f9a7a42cf35f4ffcf96","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fidals/shopelectro/pulls/20/commits","review_comments_url":"https://api.github.com/repos/fidals/shopelectro/pulls/20/comments","review_comment_url":"https://api.github.com/repos/fidals/shopelectro/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fidals/shopelectro/issues/20/comments","statuses_url":"https://api.github.com/repos/fidals/shopelectro/statuses/a8e675185ef073d701eb34545ad0edc69257398f","head":{"label":"fidals:import_catalog","ref":"import_catalog","sha":"a8e675185ef073d701eb34545ad0edc69257398f","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":57301144,"name":"shopelectro","full_name":"fidals/shopelectro","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/shopelectro","description":"shopelectro.ru site's code","fork":false,"url":"https://api.github.com/repos/fidals/shopelectro","forks_url":"https://api.github.com/repos/fidals/shopelectro/forks","keys_url":"https://api.github.com/repos/fidals/shopelectro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/shopelectro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/shopelectro/teams","hooks_url":"https://api.github.com/repos/fidals/shopelectro/hooks","issue_events_url":"https://api.github.com/repos/fidals/shopelectro/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/shopelectro/events","assignees_url":"https://api.github.com/repos/fidals/shopelectro/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/shopelectro/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/shopelectro/tags","blobs_url":"https://api.github.com/repos/fidals/shopelectro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/shopelectro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/shopelectro/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/shopelectro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/shopelectro/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/shopelectro/languages","stargazers_url":"https://api.github.com/repos/fidals/shopelectro/stargazers","contributors_url":"https://api.github.com/repos/fidals/shopelectro/contributors","subscribers_url":"https://api.github.com/repos/fidals/shopelectro/subscribers","subscription_url":"https://api.github.com/repos/fidals/shopelectro/subscription","commits_url":"https://api.github.com/repos/fidals/shopelectro/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/shopelectro/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/shopelectro/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/shopelectro/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/shopelectro/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/shopelectro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/shopelectro/merges","archive_url":"https://api.github.com/repos/fidals/shopelectro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/shopelectro/downloads","issues_url":"https://api.github.com/repos/fidals/shopelectro/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/shopelectro/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/shopelectro/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/shopelectro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/shopelectro/labels{/name}","releases_url":"https://api.github.com/repos/fidals/shopelectro/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/shopelectro/deployments","created_at":"2016-04-28T12:43:43Z","updated_at":"2016-05-12T08:41:23Z","pushed_at":"2016-06-01T15:08:14Z","git_url":"git://github.com/fidals/shopelectro.git","ssh_url":"git@github.com:fidals/shopelectro.git","clone_url":"https://github.com/fidals/shopelectro.git","svn_url":"https://github.com/fidals/shopelectro","homepage":null,"size":3005,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"fidals:master","ref":"master","sha":"4078375bbfecffd2f36fbf8271150c6741386045","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":57301144,"name":"shopelectro","full_name":"fidals/shopelectro","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/shopelectro","description":"shopelectro.ru site's code","fork":false,"url":"https://api.github.com/repos/fidals/shopelectro","forks_url":"https://api.github.com/repos/fidals/shopelectro/forks","keys_url":"https://api.github.com/repos/fidals/shopelectro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/shopelectro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/shopelectro/teams","hooks_url":"https://api.github.com/repos/fidals/shopelectro/hooks","issue_events_url":"https://api.github.com/repos/fidals/shopelectro/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/shopelectro/events","assignees_url":"https://api.github.com/repos/fidals/shopelectro/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/shopelectro/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/shopelectro/tags","blobs_url":"https://api.github.com/repos/fidals/shopelectro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/shopelectro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/shopelectro/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/shopelectro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/shopelectro/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/shopelectro/languages","stargazers_url":"https://api.github.com/repos/fidals/shopelectro/stargazers","contributors_url":"https://api.github.com/repos/fidals/shopelectro/contributors","subscribers_url":"https://api.github.com/repos/fidals/shopelectro/subscribers","subscription_url":"https://api.github.com/repos/fidals/shopelectro/subscription","commits_url":"https://api.github.com/repos/fidals/shopelectro/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/shopelectro/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/shopelectro/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/shopelectro/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/shopelectro/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/shopelectro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/shopelectro/merges","archive_url":"https://api.github.com/repos/fidals/shopelectro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/shopelectro/downloads","issues_url":"https://api.github.com/repos/fidals/shopelectro/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/shopelectro/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/shopelectro/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/shopelectro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/shopelectro/labels{/name}","releases_url":"https://api.github.com/repos/fidals/shopelectro/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/shopelectro/deployments","created_at":"2016-04-28T12:43:43Z","updated_at":"2016-05-12T08:41:23Z","pushed_at":"2016-06-01T15:08:14Z","git_url":"git://github.com/fidals/shopelectro.git","ssh_url":"git@github.com:fidals/shopelectro.git","clone_url":"https://github.com/fidals/shopelectro.git","svn_url":"https://github.com/fidals/shopelectro","homepage":null,"size":3005,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/20"},"html":{"href":"https://github.com/fidals/shopelectro/pull/20"},"issue":{"href":"https://api.github.com/repos/fidals/shopelectro/issues/20"},"comments":{"href":"https://api.github.com/repos/fidals/shopelectro/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fidals/shopelectro/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/fidals/shopelectro/statuses/a8e675185ef073d701eb34545ad0edc69257398f"}}}}
{"actor":{"display_login":"begor"}}