def no_proxy(): if request.method == 'POST': title = request.form["ocw"] long_title = media[title].split('/')[-1] filepath = urljoin("downloads/", long_title) downloader = Downloader() downloader.get(media[title], filepath) flash('Successfully downloaded {0}'.format(long_title)) return render_template('proxy.html', page_title="No proxy", action="no_proxy")
def test_rule(url, regexp=''): download = Downloader() html1 = download.get(url) #print html1 text1 = process_selector(selector, html1.text) md51 = md5(text1.encode('utf-8')) html2 = download.get(url) text2 = process_selector(selector, html2.text) md52 = md5(text2.encode('utf-8')) if md51 == md52: print 'md5 is same' else: print md51, md52
def process(rules): for rule in rules: download = Downloader() html = download.get(rule.url) if html == None: logger.error('%s无法访问'%rule.corp) continue elif rule.selector: text = process_selector(rule,html.text) elif rule.types == 'github': rule.selector = "div.commit-group-title" text = process_selector(rule,html.text) else: text = html.text if text == None: continue hash_list = dataConfig.hash_list() html_md5 = md5(text.encode('utf-8')) #text编码为unicode if debug: print 'html:',text[:20] print 'hash_list:',hash_list print 'html_md5',html_md5 if len(hash_list) > 0: if rule.corp in hash_list.keys(): if html_md5 == hash_list[rule.corp]: logger.info('%s no change'%rule.corp) else: #如果hash改变,说明有更新,发送邮件通知 logger.warning('%s has update'%rule.corp) dataConfig.update_hash(rule.corp,html_md5) context = '<a href={0}>{0}</a>'.format(rule.url) Notification(rule.message).notification(context) else: #如果不存在该corp,则添加该hash logger.info('添加新的监控app:%s'%rule.corp) dataConfig.add_hash(rule.corp,html_md5) else: #如果hash列表为空,则先初始化 logger.info('wam init ....') dataConfig.add_hash(rule.corp,html_md5)