@@ -0,0 +1,1018 @@
+from django.core.management.base import BaseCommand, CommandError%0A%0Afrom bs4 import BeautifulSoup%0Afrom django.contrib.auth.models import User%0Afrom article.models import Article, UserPostArticle%0Afrom utils import q%0A%0Aclass Command(BaseCommand):%0A    help = 'import pocket data'%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument('pocket_path', type=str)%0A%0A    def handle(self, *args, **options):%0A        print %22in process%22%0A        file_path = options%5B%22pocket_path%22%5D%0A        soup = None%0A        with open(file_path, 'r') as pocket_file:%0A            soup = BeautifulSoup(pocket_file.read())%0A%0A        user = User.objects.filter().first()%0A        for link in soup.find_all('a'):%0A            url = link.get('href')%0A%0A            article, _ = Article.objects.get_or_create(original_url=url)%0A            upa, created = UserPostArticle.objects.get_or_create(article=article, user=user)%0A            # post process in rq worker%0A            if created:%0A                q.enqueue(upa.defer_process)%0A%0A        print %22done%22%0A

add pocket manage