
import requests
import json

from just.items import JustPublication
import logging

API_KEY = 'justitie-very-secret-key'
API_PUBLICATIONS = 'http://czl-api.code4.ro/api/publications/'

class JustPublicationsToApiPipeline(object):
    def process_item(self, item, spider):

        if type(item) != JustPublication:
            return item

        r = requests.post(API_PUBLICATIONS, json=dict(item), headers={'Authorization': 'Token %s' % (API_KEY,) } )

        return item


import requests
import json
import logging

from just.items import JustPublication
import logging

API_KEY = 'justitie-very-secret-key'
API_PUBLICATIONS = 'http://czl-api.code4.ro/api/publications/'

class JustPublicationsToApiPipeline(object):
    def process_item(self, item, spider):

        if type(item) != JustPublication:
            return item

        r = requests.post(API_PUBLICATIONS, json=dict(item), headers={'Authorization': 'Token %s' % (API_KEY,) } )

        api_log = logging.getLogger('api-log.txt')
        if r.status_code == 200 or r.status_code == '200':
            api_log.log(r.status_code, level=logging.INFO)
        else:
            api_log.log(r.status_code, level=logging.ERROR)
        api_log.log(r.content, level=logging.INFO)

        return item

Add logging for api calls.
Add logging for api calls.

  
  import requests
  import json
+ import logging
  
  from just.items import JustPublication
  import logging
  
  API_KEY = 'justitie-very-secret-key'
  API_PUBLICATIONS = 'http://czl-api.code4.ro/api/publications/'
  
  class JustPublicationsToApiPipeline(object):
      def process_item(self, item, spider):
  
          if type(item) != JustPublication:
              return item
  
          r = requests.post(API_PUBLICATIONS, json=dict(item), headers={'Authorization': 'Token %s' % (API_KEY,) } )
  
+         api_log = logging.getLogger('api-log.txt')
+         if r.status_code == 200 or r.status_code == '200':
+             api_log.log(r.status_code, level=logging.INFO)
+         else:
+             api_log.log(r.status_code, level=logging.ERROR)
+         api_log.log(r.content, level=logging.INFO)
+ 
          return item
  
Add logging for api calls.
## Code Before:

import requests
import json

from just.items import JustPublication
import logging

API_KEY = 'justitie-very-secret-key'
API_PUBLICATIONS = 'http://czl-api.code4.ro/api/publications/'

class JustPublicationsToApiPipeline(object):
    def process_item(self, item, spider):

        if type(item) != JustPublication:
            return item

        r = requests.post(API_PUBLICATIONS, json=dict(item), headers={'Authorization': 'Token %s' % (API_KEY,) } )

        return item

## Instruction:
Add logging for api calls.
## Code After:

import requests
import json
import logging

from just.items import JustPublication
import logging

API_KEY = 'justitie-very-secret-key'
API_PUBLICATIONS = 'http://czl-api.code4.ro/api/publications/'

class JustPublicationsToApiPipeline(object):
    def process_item(self, item, spider):

        if type(item) != JustPublication:
            return item

        r = requests.post(API_PUBLICATIONS, json=dict(item), headers={'Authorization': 'Token %s' % (API_KEY,) } )

        api_log = logging.getLogger('api-log.txt')
        if r.status_code == 200 or r.status_code == '200':
            api_log.log(r.status_code, level=logging.INFO)
        else:
            api_log.log(r.status_code, level=logging.ERROR)
        api_log.log(r.content, level=logging.INFO)

        return item
