aboutsummaryrefslogtreecommitdiff
path: root/crawler/neodarznet/pipelines.py
blob: 36a7f1f491a90f5d481f3760ad883eeea7cf109d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- coding: utf-8 -*-
import logging

from database.models import Neodarznet


class NeodarznetPipeline(object):

    def process_item(self, item, spider):
        try:
            page = Neodarznet.get(Neodarznet.url == item['url'])
            if page.content_length != item['content_length']:
                q = Neodarznet.update(**item).where(Neodarznet.url == item['url'])
                q.execute()
                logging.info("Update item {}".format(page))
        except Neodarznet.DoesNotExist:
            page = Neodarznet.create(**item)
            logging.info("Create item {}".format(page))
        return item