def GET(self, item_id= None): r = [] if item_id: f = Feed.findById(item_id) r = f.getSelfAsDict() else: f = Feed.findAll() for i in f: r.append(i.getSelfAsDict()) return json.dumps(r) pass
def add(self, type, name, url): a = {"id":None, "type": type, "name": name, "url": url, "update_time":None, "last_update":None, "cache_file":None, "cache_type":None, "output_scheme":None, "map_rules":None, "logon":None, "password":None } q = Feed(**a) q.save()
def POST(self, type, name, url): a = {"id":None, "type": type, "name": name, "url": url, "update_time":3600, "last_update":0, "cache_file":None, "cache_type":None, "output_scheme":None, "map_rules":None, "logon":None, "password":None } q = Feed(**a) q.save() cherrypy.response.status = '201 Created'
def POST(self, type, name, url, utime, login = None, passwd = None): a = {"id":None, "enable": 0, "type": type, "name": name, "url": url, "update_time":int(utime), "last_update":0, "cache_data":0, "cache_type":None, "output_scheme":None, "map_rules":None, "logon":login, "password":passwd } q = Feed(**a) q.save() #if enable == "1": # self.cntrl.addJob(q) cherrypy.response.status = '201 Created'
def POST(self, type, name, url, utime, login=None, passwd=None): a = { "id": None, "enable": 0, "type": type, "name": name, "url": url, "update_time": int(utime), "last_update": 0, "cache_data": 0, "cache_type": None, "output_scheme": None, "map_rules": None, "logon": login, "password": passwd } q = Feed(**a) q.save() #if enable == "1": # self.cntrl.addJob(q) cherrypy.response.status = '201 Created'
def savefeed(self, item_id, schema, data, testdownload="false"): feed_item = Feed.findById(item_id) map_file = str(feed_item.id) + "_" + feed_item.name rx = re.compile('[^\d\w]') map_file = rx.sub("_", map_file) filepath = os.path.join("schemas", schema, map_file) try: yield "saving xml file..." writeToFile(content=data, filename="mapping", folder=filepath, extension=".xml", timestamp=False, overwrite=True) yield "OK" + "<br/>" feed_item.output_scheme = schema feed_item.map_rules = map_file yield "generating python code..." CodeGenerator().generateCode(feed_item) yield "OK" + "<br/>" classname = CodeGenerator.getClassName(feed_item) #folder = os.path.join("webrss","downloaders") yield "compile test..." py_compile.compile(os.path.join( os.path.join("webrss", "downloaders"), classname + ".py"), doraise=True) yield "OK" + "<br/>" feed_item.save() if testdownload == "true": yield "Testing download..." feed_item.cache_data = feed_item.cache_data - (8 * 24 * 60 * 60) m = __import__(classname) m = reload(m) out = m.Downloader().parseFeed(feed_item) p = re.compile("^([\s]+)", re.MULTILINE) yield "OK" + "<br/>" out = cgi.escape(out) out = p.sub(lambda x: (x.end() - x.start()) * "  ", out) yield out.replace("\n", "<br>") except PyCompileError, e: yield "Error in compiling:" + "<br/>" yield e.exc_type_name + "<br/>" yield e.exc_value[0] + " on line, with text: " + e.exc_value[1][ 3] + "<br/>"
def edit_feed_map(self, item_id, schema=None): item = Feed.findById(item_id) if schema: item.output_scheme = schema item.map_rules = '' m = Mapper(item) m.loadScheme() m.loadMapping() f = None if item.output_scheme: f = FeedAnalyzer() f.analyze(item, m) tmpl = lookup.get_template("edit_feed_map.html") return tmpl.render(item=item, mapper=m, pgname="edit_feed_map", flz=f)
def edit_feed_map(self, item_id, schema=None): item = Feed.findById(item_id) if schema: item.output_scheme = schema item.map_rules = '' m = Mapper(item) m.loadScheme() m.loadMapping() f = None if item.output_scheme: f = FeedAnalyzer() f.analyze(item, m) tmpl = lookup.get_template("edit_feed_map.html") return tmpl.render(item = item, mapper = m,pgname="edit_feed_map", flz = f)
def savefeed(self, item_id, schema, data, testdownload = "false"): feed_item = Feed.findById(item_id) map_file = str(feed_item.id) + "_" + feed_item.name rx = re.compile('[^\d\w]') map_file = rx.sub("_", map_file) filepath = os.path.join("schemas",schema, map_file) try: yield "saving xml file..." writeToFile(content = data, filename = "mapping", folder = filepath , extension = ".xml", timestamp = False, overwrite = True) yield "OK"+ "<br/>" feed_item.output_scheme = schema feed_item.map_rules = map_file yield "generating python code..." CodeGenerator().generateCode(feed_item) yield "OK"+ "<br/>" classname = CodeGenerator.getClassName(feed_item) #folder = os.path.join("webrss","downloaders") yield "compile test..." py_compile.compile(os.path.join(os.path.join("webrss","downloaders"),classname+".py"), doraise = True) yield "OK"+ "<br/>" feed_item.save() if testdownload == "true": yield "Testing download..." feed_item.cache_data = feed_item.cache_data - (8*24*60*60) m = __import__(classname) m = reload(m) out = m.Downloader().parseFeed(feed_item) p = re.compile("^([\s]+)", re.MULTILINE) yield "OK"+ "<br/>" out = cgi.escape(out) out = p.sub(lambda x: (x.end()-x.start())*"  ",out) yield out.replace("\n","<br>") except PyCompileError, e: yield "Error in compiling:"+ "<br/>" yield e.exc_type_name + "<br/>" yield e.exc_value[0] + " on line, with text: " + e.exc_value[1][3]+ "<br/>"
def PUT(self, id, action, f_type): #print action print id, action, f_type f = Feed.findById(id) if f_type == "f_enable": if action == "enable": f.enable = 1 f.save() self.ctrl.addJob(f) elif action == "disable": f.enable = 0 f.save() self.ctrl.removeJob(id) if f_type == "f_backup": if action == "enable": f.backup = 1 f.save() self.ctrl.updateJob(f) elif action == "disable": f.backup = 0 f.save() self.ctrl.updateJob(f)
def DELETE(self, item_id): self.cntrl.removeJob(item_id); f = Feed.findById(item_id) f.delete() cherrypy.response.status = '204 No Content'
def PUT(self, id, **kw): f = Feed.findById(id) f.updateSelf(**kw) f.save() self.cntrl.updateJob(f)
def DELETE(self, item_id): self.cntrl.removeJob(item_id) f = Feed.findById(item_id) f.delete() cherrypy.response.status = '204 No Content'
def edit_feed(self, item_id): item = Feed.findById(item_id) tmpl = lookup.get_template("edit_feed.html") return tmpl.render(item=item, pgname="edit_feed")
def loadJobs(self): f = Feed.findAll() for fd in f: if fd.enable: fd.thr = None self.addJob(fd)
def edit_feed(self, item_id): item = Feed.findById(item_id) tmpl = lookup.get_template("edit_feed.html") return tmpl.render(item = item, pgname="edit_feed")
def index(self): items = Feed.findAll() tmpl = lookup.get_template("database.html") return tmpl.render(items = items, pgname="db")
def DELETE(self, item_id): f = Feed.findById(item_id) f.delete() cherrypy.response.status = '204 No Content'
def loadJobs(self): f = Feed.findAll() for fd in f: self.addJob(fd)