# Path: malware_crawl/defaults.py
# REQUESTS_SESSIONS = {
#     "api": requests.Session(),
#     "probe": requests.Session()
# }
# 
# Path: malware_crawl/models.py
# class CaptureUrl(models.Model):
#     url_id = models.BigIntegerField(unique=True, primary_key=True)
#     url = models.CharField(max_length=6249)
#     currentstatus = models.CharField(max_length=3, blank=True)
#     lastvisittime = models.CharField(max_length=69, blank=True)
#     operation_id = models.IntegerField(null=True, blank=True)
#     class Meta:
#         db_table = u'url'


from datetime import timedelta
from six.moves import zip, map
from celery import task, current_app
from celery.contrib.batches import Batches
from malware_crawl.defaults import redis_db
from django.conf import settings
from malware_crawl.models import CaptureUrl
from malware_crawl.scan.celery_rpc_client import RevertRpcClient
import time
import cPickle as pickle
    # use mark_as_done to manually return response data
    for response, request in zip(reponses, requests):
        current_app.backend.mark_as_done(request.id, response)


def chpc_malware_scan_real(urls):
    def prepare(url):
        return url

    def request(urls):
        total_response = {}
        if not urls:
            return total_response

        CaptureUrl.objects.using('capture').all().delete()
        #TODO: do things and return url=>confidence dict
        for u in urls:
            dbu = CaptureUrl(url=u)
            dbu.save(using="capture")
        #call rpc here!
        print("calling start rpc...")
        revert_rpc = RevertRpcClient()

        r = revert_rpc.call("start")

        #test to see if all the urls are processed
        ding = False

        while not ding:
            ding = True

# Path: malware_crawl/defaults.py
# REQUESTS_SESSIONS = {
#     "api": requests.Session(),
#     "probe": requests.Session()
# }
# 
# Path: malware_crawl/models.py
# class CaptureUrl(models.Model):
#     url_id = models.BigIntegerField(unique=True, primary_key=True)
#     url = models.CharField(max_length=6249)
#     currentstatus = models.CharField(max_length=3, blank=True)
#     lastvisittime = models.CharField(max_length=69, blank=True)
#     operation_id = models.IntegerField(null=True, blank=True)
#     class Meta:
#         db_table = u'url'


# Path: malware_crawl/scan/capture_hpc.py
from datetime import timedelta
from six.moves import zip, map
from celery import task, current_app
from celery.contrib.batches import Batches
from malware_crawl.defaults import redis_db
from django.conf import settings
from malware_crawl.models import CaptureUrl
from malware_crawl.scan.celery_rpc_client import RevertRpcClient
import time
import cPickle as pickle

    # use mark_as_done to manually return response data
    for response, request in zip(reponses, requests):
        current_app.backend.mark_as_done(request.id, response)


def chpc_malware_scan_real(urls):
    def prepare(url):
        return url

    def request(urls):
        total_response = {}
        if not urls:
            return total_response

        CaptureUrl.objects.using('capture').all().delete()
        #TODO: do things and return url=>confidence dict
        for u in urls:
            dbu = CaptureUrl(url=u)
            dbu.save(using="capture")
        #call rpc here!
        print("calling start rpc...")
        revert_rpc = RevertRpcClient()

        r = revert_rpc.call("start")

        #test to see if all the urls are processed
        ding = False

        while not ding:
            ding = True

            for url in CaptureUrl.objects.using('capture').all():