def index(): forms = OrderedDict() forms['sample'] = SameDiffSample(g.current_lang) forms['upload'] = SameDiffUpload() # forms['link'] = SameDiffLink() if request.method == 'POST': btn_value = request.form['btn'] # email = None is_sample_data = False titles = [] sample_id = '' if btn_value == 'upload': files = [forms['upload'].data['upload'], forms['upload'].data['upload2']] file_paths = filehandler.open_docs(files) f1name = files[0].filename f2name = files[1].filename logger.debug("New from upload: %s & %s", f1name, f2name) both = unicode(_('%(f1)s and %(f2)s', f1=f1name, f2=f2name)) titles = [f1name, both, f2name] # email = forms['upload'].data['email'] elif btn_value == 'sample': sample_sources = [ forms['sample'].data['sample'], forms['sample'].data['sample2'] ] f1name = filehandler.get_sample_title(sample_sources[0]) f2name = filehandler.get_sample_title(sample_sources[1]) sample_id = str(f1name) + str(f2name) existing_doc_id = mongo.results_for_sample('samediff',sample_id) if existing_doc_id is not None: logger.debug("Existing from sample: %s", sample_id) return redirect(request.url + 'results/' + existing_doc_id) logger.debug("New from sample: %s", ", ".join(sample_sources)) file_paths = [ filehandler.get_sample_path(sample_source) for sample_source in sample_sources ] logger.debug(" loading from %s", ", ".join(file_paths)) is_sample_data = True both = unicode(_('%(f1)s and %(f2)s', f1=f1name, f2=f2name)) titles = [f1name, both, f2name] # email = forms['sample'].data['email'] elif btn_value == 'link': url1 = forms['link'].data['link'] url2 = forms['link'].data['link2'] if not 'http://' in url1: url1 = 'http://' + url1 if not 'http://' in url2: url2 = 'http://' + url2 file_paths = [ filehandler.write_to_temp_file(filehandler.download_webpage(url1)), filehandler.write_to_temp_file(filehandler.download_webpage(url2)) ] titles = ['1', 'both', '2'] if btn_value is not None and btn_value is not u'': return process_results(file_paths, titles, sample_id, btn_value) return render_template('samediff/samediff.html', forms=forms.items(), tool_name='samediff', max_file_size_in_mb = g.max_file_size_mb)
def process_sample(source): """ Return results for a sample file """ sample_path = filehandler.get_sample_path(source) sample_name = filehandler.get_sample_title(source) logger.debug('[CTD] Loading from: %s', sample_path) results = ctd.get_summary(sample_path) results['has_multiple_sheets'] = False results['filename'] = sample_name return results
def index(): doc_url = oauth.doc_url() if doc_url is not None: return redirect_to_results(process_link(doc_url), 'link') tab = 'paste' if not 'tab' in request.args else request.args['tab'] results = None forms = OrderedDict() forms['sample'] = WTFCSVSample(g.current_lang) forms['upload'] = WTFCSVUpload() # forms['link'] = WTFCSVLink() if request.method == 'POST': btn_value = request.form['btn'] sample_id = '' if btn_value == 'upload': upload_file = forms['upload'].data['upload'] logger.debug("New from upload: %s", upload_file.filename) results = process_upload(upload_file) elif btn_value == 'link': doc_url = forms['link'].data['link'] logger.debug("New from link: %s", doc_url) doc = oauth.open_doc_from_url(doc_url, request.url) if doc['authenticate'] is not None: return redirect(doc['authenticate']) elif doc['doc'] is not None: results = process_link(doc['doc']) elif btn_value == 'sample': sample_source = forms['sample'].data['sample'] samplename = filehandler.get_sample_title(sample_source) sample_id = sample_source existing_doc_id = mongo.results_for_sample('wtfcsv',sample_id) if existing_doc_id is not None: logger.debug("Existing from sample: %s", sample_source) return redirect(request.url + 'results/' + existing_doc_id) logger.debug("New from sample: %s", samplename) sample_path = filehandler.get_sample_path(sample_source) logger.debug(" loading from %s", sample_path) results = [] results.append(wtfcsvstat.get_summary(sample_path)) results[0]['filename'] = samplename + '.csv' if btn_value is not None and btn_value is not u'': return redirect_to_results(results, btn_value, sample_id) return render_template('wtfcsv.html', forms=forms.items(), tool_name='wtfcsv', max_file_size_in_mb = g.max_file_size_mb)
def _download_sample_data(source, filename_to_send): sample_path = filehandler.get_sample_path(source) dirname = os.path.dirname(sample_path) filename = os.path.basename(sample_path) logger.debug("download sample data from%s/%s", dirname, filename) return send_from_directory(directory=dirname, filename=filename)
def index(): words = None forms = OrderedDict() forms['sample'] = WordCounterSample(g.current_lang) forms['paste'] = WordCounterPaste('I am Sam\nSam I am\nThat Sam-I-am!\nThat Sam-I-am!\nI do not like that Sam-I-am!\nDo you like \ngreen eggs and ham?\nI do not like them, Sam-I-am.\nI do not like\ngreen eggs and ham.\nWould you like them \nhere or there?\nI would not like them\nhere or there.\nI would not like them anywhere.') forms['upload'] = WordCounterUpload() forms['link'] = WordCounterLink() if request.method == 'POST': ignore_case = True ignore_stopwords = True btn_value = request.form['btn'] sample_id = '' if btn_value == 'paste': words = forms['paste'].data['area'] ignore_case = forms[btn_value].data['ignore_case_paste'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_paste'] logger.debug("New from paste: %d chars", len(words) ) title = _('your text') elif btn_value == 'upload': upload_file = forms['upload'].data['upload'] words = process_upload(upload_file) ignore_case = forms[btn_value].data['ignore_case_upload'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_upload'] title = upload_file.filename logger.debug("New from upload: %s", title ) elif btn_value == 'sample': sample_source = forms['sample'].data['sample'] samplename = filehandler.get_sample_title(sample_source) title = samplename ignore_case = forms[btn_value].data['ignore_case_sample'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_sample'] sample_id = title+str(ignore_case)+str(ignore_stopwords) existing_doc_id = mongo.results_for_sample('wordcounter',sample_id) if existing_doc_id is not None: logger.debug("Existing from sample: %s", sample_source) return redirect(request.url + 'results/' + existing_doc_id) logger.info("New from sample: %s", sample_source) sample_path = filehandler.get_sample_path(sample_source) logger.debug(" loading from %s", sample_path) words = filehandler.convert_to_txt(sample_path) elif btn_value == 'link': url = forms['link'].data['link'] # TODO: should actually accept https if 'https://' in url: url = url.replace('https', 'http') elif not 'http://' in url: url = 'http://' + url logger.debug("New from link: %s", url) content = filehandler.download_webpage(url) words = content['text'] ignore_case = forms[btn_value].data['ignore_case_link'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_link'] title = _(content['title']) if words is not None: logger.debug(" about to process words") counts = process_words(words, ignore_case, ignore_stopwords, btn_value=='sample') logger.debug(" finished counts, about to save") doc_id = mongo.save_words('wordcounter', counts, ignore_case, ignore_stopwords, title, sample_id, btn_value) logger.debug(" saved") return redirect(request.url + 'results/' + doc_id + '?submit=true') return render_template('wordcounter.html', forms=forms.items(), tool_name='wordcounter', max_file_size_in_mb = g.max_file_size_mb)
def index(): words = None forms = OrderedDict() forms['sample'] = WordCounterSample(g.current_lang) forms['paste'] = WordCounterPaste( 'I am Sam\nSam I am\nThat Sam-I-am!\nThat Sam-I-am!\nI do not like that Sam-I-am!\nDo you like \ngreen eggs and ham?\nI do not like them, Sam-I-am.\nI do not like\ngreen eggs and ham.\nWould you like them \nhere or there?\nI would not like them\nhere or there.\nI would not like them anywhere.' ) forms['upload'] = WordCounterUpload() forms['link'] = WordCounterLink() if request.method == 'POST': ignore_case = True ignore_stopwords = True btn_value = request.form['btn'] sample_id = '' extras_to_save = {} if btn_value == 'paste': words = forms['paste'].data['area'] ignore_case = forms[btn_value].data['ignore_case_paste'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_paste'] logger.debug("New from paste: %d chars", len(words)) title = _('your text') elif btn_value == 'upload': upload_file = forms['upload'].data['upload'] words = process_upload(upload_file) ignore_case = forms[btn_value].data['ignore_case_upload'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_upload'] title = upload_file.filename logger.debug("New from upload: %s", title) elif btn_value == 'sample': sample_source = forms['sample'].data['sample'] samplename = filehandler.get_sample_title(sample_source) title = samplename ignore_case = forms[btn_value].data['ignore_case_sample'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_sample'] sample_id = title + str(ignore_case) + str(ignore_stopwords) existing_doc_id = mongo.results_for_sample('wordcounter', sample_id) if existing_doc_id is not None: logger.debug("Existing from sample: %s", sample_source) return redirect(request.url + 'results/' + existing_doc_id) logger.info("New from sample: %s", sample_source) sample_path = filehandler.get_sample_path(sample_source) logger.debug(" loading from %s", sample_path) words = filehandler.convert_to_txt(sample_path) extras_to_save = filehandler.get_sample(sample_source) elif btn_value == 'link': url = forms['link'].data['link'] # TODO: should actually accept https if 'https://' in url: url = url.replace('https', 'http') elif not 'http://' in url: url = 'http://' + url logger.debug("New from link: %s", url) content = filehandler.download_webpage(url) words = content['text'] ignore_case = forms[btn_value].data['ignore_case_link'] ignore_stopwords = forms[btn_value].data['ignore_stopwords_link'] title = _(content['title']) if words is not None: logger.debug(" about to process words") counts = _process_words(words, ignore_case, ignore_stopwords, btn_value == 'sample') logger.debug(" finished counts, about to save") doc_id = mongo.save_words('wordcounter', counts, ignore_case, ignore_stopwords, str(title), sample_id, btn_value, extras_to_save) logger.debug(" saved") return redirect(request.url + 'results/' + doc_id + '?submit=true') return render_template('wordcounter.html', forms=list(forms.items()), tool_name='wordcounter', max_file_size_in_mb=g.max_file_size_mb)
def _download_sample_data(source,filename_to_send): sample_path = filehandler.get_sample_path(source) dirname = os.path.dirname(sample_path) filename = os.path.basename(sample_path) logger.debug("download sample data from%s/%s", dirname, filename) return send_from_directory(directory=dirname, filename=filename)