djm / python-scrapyd-api

A Python wrapper for working with Scrapyd's API.
BSD 2-Clause "Simplified" License
268 stars 32 forks source link

Kwargs arguments in function schedule are empty #12

Closed amarynets closed 7 years ago

amarynets commented 7 years ago

Hi, guys. I have a problem. When I call function

self.api.schedule('exa', job.spider.sp_name, query='id=21')

I get empty kwargs, as a result I haven't an argument in my spider. What I made wrong? If I just pass argument in curl or make post request - all are working perfectly

djm commented 7 years ago

Hi @amarynets,

I'm not sure where the query kwarg you have there came from. The extra attributes to the spider are meant to be passed in as keyword arguments themselves.

So if your spider argument is called id then, based on your example it should probably be:

self.api.schedule('exa', job.spider.sp_name, id=21)

Does that make it work?

amarynets commented 7 years ago

Hi @djm, it does not help me. I try pass different arguments, but kwargs still empty. In my case, I should put id=21 as a string in variable query, because it is needed for make query to DB, instead, id=21 can be different condition, for example, id>21 and id <35

djm commented 7 years ago

Can you show me the method spec of your Spiders constructor?

On 26 Jun 2017 2:25 pm, "Andrii" notifications@github.com wrote:

Hi @djm https://github.com/djm, it does not help me. I try pass different arguments, but kwargs still empty. In my case, I should put id=21 as a string in variable query, because it is needed for make query to DB, instead, id=21 can be different condition, for example, id>21 and id <35

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/djm/python-scrapyd-api/issues/12#issuecomment-311044240, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFaqKG35CQNrk50MdsGtAVjSeCEhrYJks5sH6MigaJpZM4OFNvE .

amarynets commented 7 years ago

Sure

self.condition = kwargs.get('query')
self.query = "SELECT id, name, country FROM wp_esi_entity WHERE 1 and id=3"
        if self.condition:
            print(self.condition)
            self.query += ' or {}'.format(self.condition)
print(self.query)
self.comp = db.select(self.query)

There test query string

amarynets commented 7 years ago

If I call so ScrapydAPI().schedule('exa', 'mhn', query='id=21'), everiting is works. Thanks, @kunla from djangodevelopers slack channel But I don't know why? Here my code

class Service:
    def __init__(self):
        self.api = ScrapydAPI()

    def run_job(self, job):
        job = Job.objects.get(pk=job)
        uuid = self.api.schedule('exa', job.spider.sp_name, query='id=21')
        job.job_uuid = uuid
        job.start_time = datetime.now()
        job.status = 'RUN'
        job.save()
        return job.json()
amarynets commented 7 years ago

I'm so sorry. It was my mistake. I just used function shedule in other place and forgot pass argument query. Now all work perfectly. Thanks for help and sorry

djm commented 7 years ago

No worries at all! Glad you got it sorted. Thanks.

On 27 Jun 2017 10:08 am, "Andrii" notifications@github.com wrote:

Closed #12 https://github.com/djm/python-scrapyd-api/issues/12.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/djm/python-scrapyd-api/issues/12#event-1140021798, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFaqCSCdmSI9CjakdeA6WuhFn4GUprMks5sILiNgaJpZM4OFNvE .