z_lens = float(re.search("^\d+.\d*", c1[6].text).group()) except: z_lens = '' try: z_src = float(re.search("^\d+.\d*", c1[7].text).group()) except: z_src = '' #print "#%03i: id:%03i %s, %s, (zl: %s; zs: %s) @ %s" % (i, id, name, yr, z_lens, z_src, url) if not DEBUG and url: print "#%03i: id:%03i %s, %s, (zl: %s; zs: %s) @ %s" % (i, id, name, yr, z_lens, z_src, url) bld1 = BasicLensData( name = name, catalog = cat1, catalog_img_id = id, img_type = "CO", channel1_imgurl = url ) if z_lens: bld1.z_lens = z_lens if z_src: bld1.z_src = z_src bld1.save() else: print "~%03i: id:%03i %s, %s, (zl: %s; zs: %s) @ %s" % (i, id, name, yr, z_lens, z_src, url) except BaseException as e: print "some strange error at id:"+str(i) print str(e)
DEBUG=True print "running in debug mode: nothing will be added to database" if not DEBUG: try: cat1 = Catalog.objects.get(name="SpaceWarps") except: cat1 = Catalog( name = "SpaceWarps", description = "selected SpaceWarps Lenses") cat1.save() s = rq.Session() imgid = raw_input("img id: ") r1 = s.get("https://api.zooniverse.org/projects/spacewarp/talk/subjects/"+imgid) json = r1.json() url = json['location']['standard'] metaid = json['metadata']['id'] print "img id: %s | metaid: %s @ %s" % (imgid, metaid, url) if not DEBUG and url: bld1 = BasicLensData( name = imgid, catalog = cat1, #catalog_img_id = metaid, img_type = "CO", channel1_imgurl = url ) bld1.save()