def run(self): while True: url,tone_name= self.q.get() doc = pq(url) download_url = pq(doc.find("a#xiazai")[0]).attr("href") BeanManager.add_bean(bt = "ring_tone" , url = url , filename = tone_name) self.q.task_done() print "I am robot %s, %s done" %(self.name , tone_name)
def collect_diary(self,diary_type): print "init reader" reader = ReaderFactory.getReader(diary_type) print "begin reading" beans = reader.read() bm = BeanManager() print "adding beans" for b in beans: print "adding",b bm.add_bean(**b)
def wrapper(**kwargs): if re.match("show_.+" , attr): _ , what = attr.split("_") time = kwargs["time"] random = kwargs["random"] from_t,to_t = get_range_from_string(time) kwargs = { "bt":what, "when_created":{ "$gt":from_t, "$lt":to_t } } return BM.get_beans(kwargs)
def download_tone(url,tone_name): doc = pq(url) download_url = pq(doc.find("a#xiazai")[0]).attr("href") BeanManager.add_bean(bt = "ring_tone" , url = download_url , filename = tone_name)
def clean_diary(self): bm = BeanManager() bm.clean_beans()