Exemple #1
0
 def processSection(self, file, startwith, dt):
     logging.info("Working on section %s. Starting with '%s'." % (file, startwith))
     orbiting = []
     startfound = True
     if startwith != "":
         startwith = int(startwith)
         startfound = False
     
     src = memcache.get("src_%s" % file).replace("\r", "").split("\n")
     logging.debug("Resource %s fetched from cache." % file)
     for i in range(0, len(src), tleutil.linecount):
         if len(src[i: i + tleutil.linecount]) < 3:
             break
         noradid, name, body, timestamp = tleutil.parseTLE(src[i: i + tleutil.linecount])
         if startwith == "" and startfound:
             startwith = noradid
         if startwith == noradid:
             startfound = True
             continue
         if not startfound:
             continue
         
         if Object.gql("where noradid = :1 and section = :2", noradid, file).count() == 0:
             obj = Object(noradid=noradid, name=name, section=file, orbiting=True)
             obj.put()
             logging.debug("New object %d (%s) discovered." % (noradid, name))
         memcache.set(key="name_%d" % noradid, value=name, time=24*3600)
         
         if TLE.gql("where noradid = :1 and timestamp = :2", noradid, timestamp).count() == 0:
             tle = TLE(noradid=noradid, section=file, body=body, timestamp=timestamp)
             tle.put()
             logging.debug("Writing new TLE for object %d." % (noradid))
         memcache.set(key="tle_%d" % noradid, value=body, time=24*3600)
         
         orbiting.append(noradid)
         
         if dt + timedelta(seconds = 10) < datetime.now():
             for obj in Object.gql("where section = :1 and noradid < :2 and noradid > :3", file, noradid, startwith):
                 if obj.noradid not in orbiting:
                     obj.orbiting = False
                     obj.put()
                     logging.debug("Object %d (%s) has decayed." % (obj.noradid, obj.name))
             logging.info("Section %s processor nearing expiration, returning at %d (%s)" % (file, noradid, name))
             return str(noradid)
     
     for obj in Object.gql("where section = :1 and noradid > :2", file, startwith):
         if obj.noradid not in orbiting:
             obj.orbiting = False
             obj.put()
             logging.debug("Object %d (%s) has decayed." % (obj.noradid, obj.name))
     logging.info("Section %s successfully processed." % file)
     return ""
Exemple #2
0
 def get(self):
     query = Object.gql("where orbiting = :1 order by noradid asc", True)
     count = 0
     while True:
         result = query.fetch(1000)
         count += len(result)
         if len(result) < 1000:
             break
         cursor = query.cursor()
         query.with_cursor(cursor)
     memcache.set(key='count', value=str(count), time=24*3600)