From 9712e3eeb5ae1acb3790a4004c3113f32a8c4033 Mon Sep 17 00:00:00 2001 From: Coding with Peter Date: Wed, 17 May 2023 08:53:54 -0700 Subject: [PATCH] features to flask srv. degrees.py started --- 104ab42f11_md/media/image1.png | Bin 0 -> 338 bytes 104ab42f11_md/media/image2.png | Bin 0 -> 2112 bytes degrees.py | 164 +++++++++++++++++++++++++++++++++ interactive.py | 31 ++++++- server.py | 14 ++- templates/basic.html | 14 +++ templates/convert.html | 17 ++++ 7 files changed, 232 insertions(+), 8 deletions(-) create mode 100644 104ab42f11_md/media/image1.png create mode 100644 104ab42f11_md/media/image2.png create mode 100644 degrees.py create mode 100644 templates/basic.html create mode 100644 templates/convert.html diff --git a/104ab42f11_md/media/image1.png b/104ab42f11_md/media/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..1f3dae6250e53d662755935c70821d954158804a GIT binary patch literal 338 zcmeAS@N?(olHy`uVBq!ia0vp^{2(?58;~rMGjRk`jKx9jP7LeL$-D$|SkfJRfr1MyxtX5*aw z@sc8kmm7%OE_7Cz$mn6LRq?4l`0b+q=Kmdb-uM4A|HiiO|Eo2`B^h$}{j7Jrr_!bz za9Bd3&T!BF0|yi|4zN8nHmIrnJ+Cn|VgjRL(%}i_noW!k-`tOvtTQe&-q19si~G;t zvmd_7Ycrc`x145KC?OH|HZwh`?(-D$lXZ5+HhIVKGrD%-;iMEooceUQ#qN=)6L`69g| efVEIUg2Clb1M>^D$bCRBGkCiCxvXPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2h~YLK~#8N?VU|_ z)Ho1;o0$s)ZU9+k7g(|kH-H==S4fsKyKn?J0&LllBLKTBlPuYh+#sXRUFxx`OK#h3 z*^;C0y?Xv>w65&zxmv!(7%=tfm8255By-jM`AeYI-nrFP=Nr zWrbKuLt^#hVl@NMy;;UVqm#<`s*TylIhynHbJ<(-;>8Qu8yBYx*;}K_Ed*eW3;!Q` zl%C3*UWjM1%?e_}&!0c5*@XN1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zKMtExyh%0iHT*tf9ESs50>>X1MSyg`V#ufH7A83ST2a3-d90f zZ&{+;zc3W5x6{yFT^tr@DMs#F*q4Ais*(iUl?CVd-1?qNwb>?5Hn}|wY7H(K(=d2E zK0e-zb6B&n2D9K4&F5uIGd7lc>Lc>~LM(>PUZ*tMym%PZOY8^=pXWUK&))a)mX2R6 q^D*Y|@UV(O7Z(>LwiIHpTKxykS@*u; 0 else 0 + return progress_percent + diff --git a/interactive.py b/interactive.py index e74efd0..5e54a1b 100644 --- a/interactive.py +++ b/interactive.py @@ -16,6 +16,15 @@ from canvas_secrets import flask_secretkey from content import my_site + + + +### SET THIS ENV VAR TO GET RELOADING +# (win) +# set FLASK_ENV=development +# (linux) +# export FLASK_ENV=development + import socket this_host = socket.gethostname() @@ -155,6 +164,15 @@ def flask_thread(q): return image_crop(filename,x,y,w,h,newname) + @app.route('/md', methods=['GET', 'POST']) + def convert_markdown(): + if request.method == 'POST': + markdown_input = request.form.get('markdown_input', '') + html_output = markdown.markdown(markdown_input) + return render_template('basic.html', title='md -> html', html_output=html_output) + return render_template('convert.html') + + # # SAVING STUFF @@ -166,10 +184,13 @@ def flask_thread(q): path = request.form['path'] txt = request.form['content'] - o3 = codecs.open(server.writing_path + path, 'r', 'utf-8') - orig_text = o3.read() - o3.close() - + try: + o3 = codecs.open(server.writing_path + path, 'r', 'utf-8') + orig_text = o3.read() + o3.close() + except Exception as e: + orig_text = '' + bu_filename = server.writing_path + 'older_copies/' + path + '_' + now + '.md' o2 = codecs.open( bu_filename, 'w', 'utf-8' ) o2.write(orig_text) @@ -321,7 +342,7 @@ def flask_thread(q): - socketio.run(app, host= '0.0.0.0') + socketio.run(app, host= '0.0.0.0') # , debug=True diff --git a/server.py b/server.py index 5aaaba7..318937f 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,6 @@ import json, codecs, re, markdown, os, pypandoc, striprtf, sqlite3, random, urllib import subprocess, html, time +from markdownify import markdownify as md from striprtf.striprtf import rtf_to_text from flask import render_template, Response from flask import send_from_directory @@ -145,8 +146,9 @@ def screenoff(): br = "
" nl = "\n" -style = """ +style = """ + """ @@ -188,6 +190,7 @@ def homepage(): a('Pi frame on','/displaypi/on') + br + br + \ a('Pi frame off','/displaypi/off') + br + br + \ a('Knowledge Base','/x/writing/index') + br + \ + a('Markdown -> HTML converter','/md') + br + \ a('Gav web mirror','/mirror') + br + \ a('Graph of users','/x/user/1') + "
" + \ a('Courses in a dept','/x/dept/csis') + "
" + \ @@ -262,7 +265,12 @@ def writing(fname): #output = pypandoc.convert_file('C:/Users/peter/Nextcloud/Documents/writing/' + fname, 'html', output = pypandoc.convert_file(writing_path + fname, 'html', extra_args=['--extract-media=%s' % hash ]) # file:///c:/Users/peter/Nextcloud/Documents/writing - return style + output + output2 = pypandoc.convert_file(writing_path + fname, 'markdown', + extra_args=['--extract-media=%s' % hash+'_md' ]) # file:///c:/Users/peter/Nextcloud/Documents/writing + new_fname = fname[:-5] + '.md' + #as_md = md(output) + return style + output + in_form(editor(output2),new_fname) + return style + markdown.markdown( "".join( [ orgline(x) for x in inp.readlines() ] ) ) diff --git a/templates/basic.html b/templates/basic.html new file mode 100644 index 0000000..403333f --- /dev/null +++ b/templates/basic.html @@ -0,0 +1,14 @@ + + + + {{ title }} + + + +

Converted HTML Output

+
{{ html_output|safe }}
+ + \ No newline at end of file diff --git a/templates/convert.html b/templates/convert.html new file mode 100644 index 0000000..0c421b8 --- /dev/null +++ b/templates/convert.html @@ -0,0 +1,17 @@ + + + + Markdown to HTML Converter + + + +

Markdown to HTML Converter

+
+
+ +
+ + \ No newline at end of file