Exemplo n.º 1
0
	def post(self):
		res = Res()
		
		try:
			s = json.loads(self.request.body)
		except ValueError as e:
			print e
			self.finish(res.emit())
			return
		
		id_ = s['id']
		del s['id']
		
		print "update config"
		
		f = open(os.path.join(scraper_dir, id_, "conf.json"), 'rb')
		schema = Schema(json.loads(f.read())['url'])
		f.close()
		
		should_activate = None
		for key in s.keys():
			if key == "is_active":
				should_activate = s[key]
				continue
			
			if type(s[key]) == dict:
				val = getattr(schema, key)
				
				for key_ in s[key].keys():
					val[key_] = s[key][key_]

				schema.setattr(key, val)			
			else:
				schema.setattr(key, s[key])
		
		schema.save()
		
		if should_activate is not None:
			print "with activation: %s!" % should_activate
			schema.activate(activate=should_activate)
			
		res.result = STATUS_OK[0]
		print res.emit()
		self.finish(res.emit())
Exemplo n.º 2
0
	def post(self):
		res = Res()
		
		if not self.validateRequest():
			self.finish(res.emit())
			return
		
		try:
			s = json.loads(self.request.body)['manifest']
		except ValueError as e:
			print e
			self.finish(res.emit())
			return
		
		url = s['url']
		del s['url']
		
		as_test = False
		try:
			as_test = s['confirm']
			print "found confirm directive: %s" % as_test
			del s['confirm']
		except KeyError as e:
			print "no confirm directive"
			print e
			pass
		
		as_test = True
		
		if not as_test:
			schema = Schema(url, create=True, **s)
			schema.save()
				
			self.finish(schema.activate())
		else:
			schema = Schema(url, create=False, as_test=True, **s)
			print json.dumps(schema.emit())
			self.finish(schema.scrape(as_test=True))