# Path: skymorph/skymorph.py
# SEARCH_TARGET_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobssel.pl?target=%s&NEAT=on&OE_EPOCH=&OE_EC=&OE_QR=&OE_TP=&OE_OM=&OE_W=&OE_IN=&OE_H='
# SEARCH_EPHEM_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobssel.pl?target=&NEAT=on&OE_EPOCH=%s&OE_EC=%s&OE_QR=%s&OE_TP=%s&OE_OM=%s&OE_W=%s&OE_IN=%s&OE_H=%s'
# SEARCH_POS_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/obssel.pl?position=%s,%s&time=%s&time_delta=1'
# IMAGE_QUERY_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobsdisp.pl'
# NEAT_FIELDS_LARGE = ['obs_id', 'triplet', 'time', 'predicted_ra', 'predicted_dec', \
#     'center_ra', 'center_dec', 'mag', 'veloc_we', 'veloc_sn', 'offset', \
#     'pos_err_major', 'pos_err_minor', 'pos_err_ang', 'pixel_loc_x', \
#     'pixel_loc_y', 'key']
# NEAT_FIELDS_SMALL = ['obs_id', 'ra', 'dec', 'time', 'exposure', 'triplet', 'key']
# NUMERIC_NEAT_FIELDS = set(['mag', 'offset', 'veloc_we', 'veloc_sn', \
#     'pixel_loc_x', 'pixel_loc_y'])
# DMS_NEAT_FIELDS = set(['center_dec', 'predicted_dec'])
# HMS_NEAT_FIELDS = set(['center_ra', 'predicted_ra'])
# URL_BASE = 'http://skyview.gsfc.nasa.gov/'
# IMAGE_SIZE = 500   # pixels
# IMAGE_PARSING_REGEX = re.compile("img src='(.*?)'")
# REDIS_PREFIX = 'skymorph'
# def images_for(target, n=10):
# def search_target(target):
# def search_ephem(epoch, ecc, per, per_date, om, w, inc, h):
# def search_position(ra, dec, time):
# def parse_results_table(text, neat_fields):
# def hms_str_to_float(hmsfield):
# def dms_str_to_float(dmsfield):
# def get_fast_image(key):
# def get_image(key):
# def get_image_info(key):


import sys
import os
import random
import pymongo
import astrometry
from pymongo import Connection
from datetime import datetime
from threading import Thread
from skymorph import skymorph
    print 'crawl', target

    #skymorph.images_for(prov_des)

    results = skymorph.search_target(target)
    groups = []
    last_group = []
    last_time = None
    for result in results:
      time = datetime.strptime(result['time'], '%Y-%m-%d %H:%M:%S')
      if last_time:
        tdelta = time - last_time if time > last_time else last_time - time
        if tdelta.total_seconds() / 60 > 45:
          # not within 45 minutes of each other
          groups.append(last_group)
          last_group = []
        else:
          last_group.append(result)
      last_time = time

    groups_final_datastructure = []
    gcount = 1
    for group in groups:
      threads = []
      group_results = []
      rcount = 1
      if len(group) < 2:
        continue
      for result in group:
        center_ra = skymorph.hms_str_to_float(result['center_ra'])

# Path: skymorph/skymorph.py
# SEARCH_TARGET_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobssel.pl?target=%s&NEAT=on&OE_EPOCH=&OE_EC=&OE_QR=&OE_TP=&OE_OM=&OE_W=&OE_IN=&OE_H='
# SEARCH_EPHEM_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobssel.pl?target=&NEAT=on&OE_EPOCH=%s&OE_EC=%s&OE_QR=%s&OE_TP=%s&OE_OM=%s&OE_W=%s&OE_IN=%s&OE_H=%s'
# SEARCH_POS_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/obssel.pl?position=%s,%s&time=%s&time_delta=1'
# IMAGE_QUERY_URL = 'http://skyview.gsfc.nasa.gov/cgi-bin/skymorph/mobsdisp.pl'
# NEAT_FIELDS_LARGE = ['obs_id', 'triplet', 'time', 'predicted_ra', 'predicted_dec', \
#     'center_ra', 'center_dec', 'mag', 'veloc_we', 'veloc_sn', 'offset', \
#     'pos_err_major', 'pos_err_minor', 'pos_err_ang', 'pixel_loc_x', \
#     'pixel_loc_y', 'key']
# NEAT_FIELDS_SMALL = ['obs_id', 'ra', 'dec', 'time', 'exposure', 'triplet', 'key']
# NUMERIC_NEAT_FIELDS = set(['mag', 'offset', 'veloc_we', 'veloc_sn', \
#     'pixel_loc_x', 'pixel_loc_y'])
# DMS_NEAT_FIELDS = set(['center_dec', 'predicted_dec'])
# HMS_NEAT_FIELDS = set(['center_ra', 'predicted_ra'])
# URL_BASE = 'http://skyview.gsfc.nasa.gov/'
# IMAGE_SIZE = 500   # pixels
# IMAGE_PARSING_REGEX = re.compile("img src='(.*?)'")
# REDIS_PREFIX = 'skymorph'
# def images_for(target, n=10):
# def search_target(target):
# def search_ephem(epoch, ecc, per, per_date, om, w, inc, h):
# def search_position(ra, dec, time):
# def parse_results_table(text, neat_fields):
# def hms_str_to_float(hmsfield):
# def dms_str_to_float(dmsfield):
# def get_fast_image(key):
# def get_image(key):
# def get_image_info(key):


# Path: stackblink/crawl.py
import sys
import os
import random
import pymongo
import astrometry
from pymongo import Connection
from datetime import datetime
from threading import Thread
from skymorph import skymorph

    print 'crawl', target

    #skymorph.images_for(prov_des)

    results = skymorph.search_target(target)
    groups = []
    last_group = []
    last_time = None
    for result in results:
      time = datetime.strptime(result['time'], '%Y-%m-%d %H:%M:%S')
      if last_time:
        tdelta = time - last_time if time > last_time else last_time - time
        if tdelta.total_seconds() / 60 > 45:
          # not within 45 minutes of each other
          groups.append(last_group)
          last_group = []
        else:
          last_group.append(result)
      last_time = time

    groups_final_datastructure = []
    gcount = 1
    for group in groups:
      threads = []
      group_results = []
      rcount = 1
      if len(group) < 2:
        continue
      for result in group:
        center_ra = skymorph.hms_str_to_float(result['center_ra'])

        center_dec = skymorph.dms_str_to_float(result['center_dec'])