{"id":580,"date":"2019-01-29T18:57:59","date_gmt":"2019-01-29T09:57:59","guid":{"rendered":"http:\/\/idealive.jp\/blog\/?p=580"},"modified":"2019-01-29T18:59:14","modified_gmt":"2019-01-29T09:59:14","slug":"%e3%80%90django%e3%80%91ameba%e3%83%96%e3%83%ad%e3%82%b0%e3%81%aerss%e3%83%aa%e3%83%bc%e3%83%80%e3%83%bc%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/idealive.jp\/blog\/2019\/01\/29\/%e3%80%90django%e3%80%91ameba%e3%83%96%e3%83%ad%e3%82%b0%e3%81%aerss%e3%83%aa%e3%83%bc%e3%83%80%e3%83%bc%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f\/","title":{"rendered":"\u3010Django\u3011Ameba\u30d6\u30ed\u30b0\u306eRSS\u30ea\u30fc\u30c0\u30fc\u3092\u4f5c\u3063\u3066\u307f\u305f"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f sohnishi \u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fDjango\u3067Ameba\u30d6\u30ed\u30b0\u306eRSS\u30ea\u30fc\u30c0\u30fc\u3092\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>Ameba\u30d6\u30ed\u30b0\u306f\u3001<\/p>\n<blockquote><p><a href=\"https:\/\/ameblo.jp\/\">http:\/\/ameba.jp<\/a>\/\u3010ID\u3011\/rss.html<\/p><\/blockquote>\n<p>\u3067\u3001RSS\u30d5\u30a3\u30fc\u30c9\u306e\u53d6\u5f97\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u4f55\u3089\u96e3\u3057\u3044\u3053\u3068\u306f\u306a\u304f\u3001<\/p>\n<blockquote><p><strong>django-feedparser<\/strong><\/p><\/blockquote>\n<p>\u3092\u4f7f\u3046\u3068\u7c21\u5358\u306b\u51fa\u6765\u3061\u3083\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:python decode:true\" title=\"getItems.py\">from django.core.management import BaseCommand\r\nfrom Hogehoge import models\r\nimport feedparser\r\n\r\nclass Command(BaseCommand):\r\n\r\n    def add_arguments(self, parser):\r\n        parser.add_argument('op1')\r\n        parser.add_argument('--op2')\r\n\r\n    def handle(self, *args, **options):\r\n\r\n        idx = models.Index.objects.all().first()\r\n        max = models.Blog.objects.all().order_by(\"-id\")[0]\r\n        if max.pk == idx.pk:\r\n            idx.value = 1\r\n        else:\r\n            idx.value += 1\r\n            idx.save()\r\n\r\n        blog = models.Blog.objects.all().filter(\r\n            id=idx.value,\r\n        ).first()\r\n        rss_link = blog.link + \"rss.html\"\r\n        feeder = feedparser.parse(rss_link)\r\n\r\n        for entry in feeder['entries']:\r\n            item = models.Item.objects.get_or_create(\r\n                blog_id=idx,\r\n                link=entry['link'],\r\n                defaults={\r\n                    'title': entry['title'],\r\n                    'description': entry['description'],\r\n                    'date': entry['date']\r\n                },\r\n            )<\/pre>\n<p>\u3042\u3068\u306fcron\u3067\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u3057\u3066\u3042\u3052\u308c\u3070\u3001\u81ea\u52d5\u3067\u304c\u3055\u304c\u3055\u62fe\u3063\u3066\u304d\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>get_or_create\u3067\u91cd\u8907\u3082\u3057\u306a\u3044\u4f5c\u308a\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001\u3010<strong>\u30b5\u30af\u30c3\u3068<\/strong>\u3011\u4f5c\u3063\u3066\u307f\u305fRSS\u30ea\u30fc\u30c0\u30fc\u306e\u3054\u7d39\u4ecb\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f sohnishi \u3067\u3059\u3002 \u4eca\u56de\u306fDjango\u3067Ameba\u30d6\u30ed\u30b0\u306eRSS\u30ea\u30fc\u30c0\u30fc\u3092\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 Ameba\u30d6\u30ed\u30b0\u306f\u3001 http:\/\/ameba.jp\/\u3010ID\u3011\/rss.html \u3067\u3001RSS\u30d5\u30a3\u30fc\u30c9\u306e&#8230;<a class=\"read-more-link button\" href=\"https:\/\/idealive.jp\/blog\/2019\/01\/29\/%e3%80%90django%e3%80%91ameba%e3%83%96%e3%83%ad%e3%82%b0%e3%81%aerss%e3%83%aa%e3%83%bc%e3%83%80%e3%83%bc%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f\/\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":3,"featured_media":582,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4,3,1],"tags":[],"class_list":["post-580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","category-python","category-3","category-1"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/580"}],"collection":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/comments?post=580"}],"version-history":[{"count":2,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":583,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/580\/revisions\/583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media\/582"}],"wp:attachment":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media?parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/categories?post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/tags?post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}