def test_html_to_tables(self): for file in os.listdir(self.static_path): if file.endswith('.html'): html_path = os.path.join(self.static_path, file) rst = dashtable.html2rst(html_path) md = dashtable.html2md(html_path) rst_name = os.path.splitext(file)[0] + '.rst' rst_path = os.path.join(self.static_path, rst_name) rst_file = open(rst_path, 'r', encoding='utf-8') rst_text = rst_file.read().rstrip() rst_file.close() try: self.assertEqual(rst, rst_text) except AssertionError: print('MATCH ERROR: ' + ntpath.basename(html_path)) md_name = os.path.splitext(file)[0] + '.md' md_path = os.path.join(self.static_path, md_name) md_file = open(md_path, 'r', encoding='utf-8') md_text = md_file.read().rstrip() md_file.close() try: self.assertEqual(md, md_text) except AssertionError: print('MATCH ERROR: ' + ntpath.basename(html_path))
def multiple_search(store=False, file=None, readfile=False): global f if file and store: f = open(file, "w") nums = [x for x in open(readfile, "r").read().split("\n") if x is not ""] for num in nums: print("\n<--[ Searching Details For {} ]-->".format(num), end="\n\n") try: r = get(api.format(number=num), verify=False) raw = r.content.decode() data = "<table>" + raw.split("<table>")[1].split( "</table>")[0] + "</table>" op = html2rst(data) if store and file: f.write("Phone Number Details For : {}\n".format(num)) f.write(op) f.write( "\n\n===============================================================\n\n" ) pass else: print(op) except HTTPError as e: print("[x] Check Your Internet Connection") if file and store: print("Saved seach result to {}".format(file)) pass
def build_rst(doc=None): from com.sun.star.beans import PropertyValue if not doc: document = XSCRIPTCONTEXT.getDocument() else: document = doc html_url = os.path.join(os.path.expanduser('~'), 'temp.html') html_url = html_url.replace('\\', '/') if not html_url.startswith('/'): save_url = 'file:///' + html_url else: save_url = 'file://' + html_url props = [PropertyValue(Name='FilterName', Value='HTML (StarCalc)')] document.storeToURL(save_url, props) rst = html2rst(html_url, force_headers=True) rst_url = os.path.join(os.path.expanduser('~'), '.ascii_table.txt') rst_url = rst_url.replace('\\', '/') f = open(rst_url, 'w') f.write(rst) f.close() os.remove(html_url) if sys.platform == "win32": subprocess.call(['start',"", rst_url], shell=True) else: subprocess.call(['xdg-open', rst_url])
def search_single(number, store=False, file=None): print("<--[ Searching Details For {} ]-->".format(number), end="\n\n") try: r = get(api.format(number=number)) raw = r.content.decode() data = "<table>" + raw.split("<table>")[1].split("</table>")[0] + "</table>" op = html2rst(data) if store and file: with open(file, "w") as f: f.write("Phone Number Details For : {}\n\n".format(number)) f.write(op) f.close() print("[!] Search Result is stored in {}".format(file)) else: print(op) except HTTPError as e: print("[x] Check Your Internet Connection") pass
def get_question(self, content, info, question_number, quiz_name): state = info.find('div', {"class": "state"}).text grade = info.find('div', {"class": "grade"}).text formulation = content.find('div', {'class': "formulation"}) answer = content.find('textarea', {"class": "coderunner-answer"}).text test_cases = self.has_tests(content) if test_cases: examples_table = self.get_examples_table(test_cases) parsed_table = html2rst(examples_table.__str__().replace('"""', '"'), force_headers=False) question_payload = {"question_number": question_number, "mark": grade, "answer": answer, "completed": state, "examples": parsed_table if test_cases else '', "question": formulation.find('p').text} self.write_template_to_file(question_payload, 'question.template', 'question{}.py'.format(question_number), quiz_name)
from dashtable import html2rst, html2md import subprocess import os for file in os.listdir(os.getcwd() + '/test_files'): if file.endswith('.html'): path = os.path.join(os.getcwd(), 'test_files', file) f = open(path, 'r') lines = f.readlines() f.close() string = ''.join(lines) converted_rst = html2rst(string) converted_md = html2md(string) md_name = os.path.splitext(path)[0] + '.md' md_file = open(md_name, 'r') md_lines = md_file.readlines() md_file.close() md_string = ''.join(md_lines).rstrip() if not md_string == converted_md: print('MarkDown Error: ' + file) rst_name = os.path.splitext(path)[0] + '.rst' rst_file = open(rst_name, 'r') rst_lines = rst_file.readlines() rst_file.close() rst_string = ''.join(rst_lines).rstrip() if not rst_string == converted_rst:
from dashtable import html2rst, html2md import subprocess import os for file in os.listdir(os.getcwd() + '/test_files'): if file.endswith('.html'): path = os.getcwd() + '/test_files/' + file f = open(path, 'r') lines = f.readlines() f.close() string = ''.join(lines) print(file) print(html2rst(string)) print('\n') print(html2md(string)) print('\n') script = os.path.join(os.getcwd(), 'dashtable/html2rst.py') filename = os.path.splitext(file)[0] outfile = os.path.join(os.getcwd(), 'test_files', filename + '.txt') subprocess.call(['python', script, path, outfile])
def render_rst(self): return dashtable.html2rst(self.render_html())