aboutsummaryrefslogtreecommitdiff
path: root/crawler/neodarznet/pipelines.py
blob: fbfebbb8832ac9a7207a76ec4e0a270ab3ecc067 (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'])
            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))
        logging.info('Item {} stored in db'.format(page))
        return item