-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto1.py
904 lines (693 loc) · 50.8 KB
/
proto1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
from flask import Flask, render_template, request,jsonify, Response, redirect, url_for
from pylatex import Document, Section, Subsection, Command, Figure, Package, Head, PageStyle, Foot,simple_page_number,NewPage, HugeText, MiniPage, SmallText, Enumerate, Itemize, Description, LargeText
from PyPDF2 import PdfFileWriter, PdfFileReader
from pylatex.utils import bold, italic, NoEscape
import os
import json
import pprint
import re
import PyPDF2
import base64
import urllib.request
app = Flask(__name__)
title_name = "";
num = 3;
@app.route("/img")
def img():
file_path = 'static/img/'
url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSEhUTExMVFRUWFxUVGBUVFxcVFRYVFRUWFhUVFRUYHSggGBolHRUVITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OGhAQGi0lHyUtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLf/AABEIAOAA4QMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAADBAIFBgEAB//EAD4QAAEDAgUBBgQEBAMJAQAAAAEAAhEDIQQFEjFBUQYiYXGBkROhsfAywdHhFEJS8WKCohUjJHKSssLS4gf/xAAZAQADAQEBAAAAAAAAAAAAAAAAAQIDBAX/xAAmEQACAgMBAAICAQUBAAAAAAAAAQIRAyExEgRBE1EiMkJScYEU/9oADAMBAAIRAxEAPwD6lgirIFV1IQnWuXPHhZIrmpRc5RLk7HQT4ii56GuEpBR1z1HUoOK5KBkiVzWl6+Ka3lUeY5+1nKVmuPDKfC9r4sN3KoMz7QNbystmPaB9QwxL4fKKtYy6bqHK+HasGPEryMbxWevqGGSo4fKqlUy6VoMp7OtZEhaOhhGtFgmo/syyfLfIKkZzLezwHC0mFwbW8I7WKSpKjjcm+kpAWR7U5q5xNKmYaPxOG58BHCtO0GZfCYY/EbDz5Pp+YWMbWm26yyTrRrjg3sv+xeMcHOpOMgjU2TJBG49vote2ovnGBqaa9JzeHNG+8mCI8ivoKeF/xFmVSGHPQXuU2qLwtTEGvQpBq45AHoXCFwOQK+JDdygpRb4NhwQ6uKa3crOZj2gawG6yOYdp3vOll1LmkdmL4MpblpH0b/arOq8vlX8TiV1T+Q3/APJi/wAkfZWtRhZcK4VoeXRxxUCUUBccEARDlFzkOtiGtG6oM07QMZyk3RtjwSm9Iu62KDdyqPMs+azlZLMM/qVDDAULB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VNkeWW1Mphu0SqpmKsi06rnITE0Wja9hPiD5/f1Qa7hO9lAM6nf7lCqUCeU3JkqKBVcRBj780NoLjBRX0YIKJqAUO2XpEzTaLcrSdksPL/JZmncrcdjWQSYRBXJESei+dhiLpeswndXD2SlKlE8LsMCudSEIdAwnX4Z3RC+AUAcom+ynWcCVL4JCgGmUAde2yXDBKZeDyoVWRskBOR4LyW0leRYiipMLjtsjg7eCawLmgOjlccwBsrkjE62zOZ3qc4RsF4Y6AAT6JnOTDVnXGdkcGtoZzGoSJGyqdXW6sqJBBG/ifyVfiCAYCKGhWqyfNCc07eP0/uiuepEIARqzeynRcE4ylKG/BCUws5pEm3h7WRaVMc9VxuG5BRmUzEFArJOogC3K5Slv0XeFINRRNhm1CQJUm1uqWqnhSaeqBBn1JQm+K49wIsiNakwDYTdb3szDW+aw2BpSVssBU0wFWPpMzaU7hEfTACrsHibBPGsHBdRjRA3XKlMHZRbK7TqXQBw0lz+Fi6O+oEvUxBjdMANaClnhGbJXKlEhIAWlq8uaF1AGfoOiQvVa/dPgvNpHaUviKdi1cmzpKZj/jOIcbBI4zARsbIxim4xdDOMLrGyRf8AorKlfT3R7oQeOU1iqF0pVww4QgBvcOi8XACeVylRMzwEd1GQqolsUALbjlTa6bFEdShCbUBdHROhWHwrYm+yl8S+9kAVAJXmd9symIZdVC6wwLpZzBIvx81OuII8B9UgOipKm4Sl8OOvCbH9SQWepthGbUSdSoSmaDJSYizywElXjahkKqwQgSmaFXvIXAZu8n7zbqwpMDSqnIX2VwRBuuuPDB9O1RNghfA08o3xAFF7pTEAcvMaIXiFFjboAMxsBDfXGyM4wlNOopDJ2XF34JXkAf/Z"
#url = "http://127.0.0.1:5000/b6f95861-d65f-4b1f-8ab6-a310ae577824"
file_name = "test"
full_path = file_path + file_name + '.jpg'
urllib.request.urlretrieve(url,full_path) # download to path
#img(url,'static/img/',file_name)
#base_image = new Image();
#base_image = /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSEhUT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LpeswndXD2SlKlE8LsMCudSEIdAwnX4Z3RC+AUAcom+ynWcCVL4JCgGmUAde2yXDBKZeDyoVWRskBOR4LyW0leRYiipMLjtsjg7eCawLmgOjlccwBsrkjE62zOZ3qc4RsF4Y6AAT6JnOTDVnXGdkcGtoZzGoSJGyqdXW6sqJBBG/ifyVfiCAYCKGhWqyfNCc07eP0/uiuepEIARqzeynRcE4ylKG/BCUws5pEm3h7WRaVMc9VxuG5BRmUzEFArJOogC3K5Slv0XeFINRRNhm1CQJUm1uqWqnhSaeqBBn1JQm+K49wIsiNakwDYTdb3szDW+aw2BpSVssBU0wFWPpMzaU7hEfTACrsHibBPGsHBdRjRA3XKlMHZRbK7TqXQBw0lz+Fi6O+oEvUxBjdMANaClnhGbJXKlEhIAWlq8uaF1AGfoOiQvVa/dPgvNpHaUviKdi1cmzpKZj/jOIcbBI4zARsbIxim4xdDOMLrGyRf8AorKlfT3R7oQeOU1iqF0pVww4QgBvcOi8XACeVylRMzwEd1GQqolsUALbjlTa6bFEdShCbUBdHROhWHwrYm+yl8S+9kAVAJXmd9symIZdVC6wwLpZzBIvx81OuII8B9UgOipKm4Sl8OOvCbH9SQWepthGbUSdSoSmaDJSYizywElXjahkKqwQgSmaFXvIXAZu8n7zbqwpMDSqnIX2VwRBuuuPDB9O1RNghfA08o3xAFF7pTEAcvMaIXiFFjboAMxsBDfXGyM4wlNOopDJ2XF34JXkAf/Z"
#fh = open("imageToSave.png", "wb")
#fh.write((base_image)) #str.decode
#fh.close()
#video_stream = "hello"
#with open('file.webm', 'w') as f_vid:
# f_vid.write(base64.b64encode(video_stream))
#with open('file.webm', 'r') as f_vid:
# video_stream = base64.b64decode(f_vid.read())
#img = /9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxIQEhITEhMQFRAQEA8PDxAPEA8PDxAPFRUWFhUVFRUYHSggGBolGxUVITEhJSkrLi4uFx81ODMsNygtLisBCgoKDg0OGhAQFy0dHR0tKy0tLSsrLS0tLS0rLS0tL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YYSvxTVmriiaGuDGuLru5Jtj9099Frt5dTaM4/md91bdD054bb4j7drqanoLdE0poiBYYUbXoth0oBxt3TRtJ5fojIKeyNZALJaPZTDFZFsCmdBZbEaonAWWUuxaDUyZHGpHMXTAtkoTQb4SoXRkI17kNJIqJEtqIyrEBT6d1kwiqFixBCY5romNwWLEjFQuCNZKFpYg0zZFI2RYsSN38VaMixYgOXPUMkixYgIHuuCD1SeopRc4CxYlTgaWnHogaxgssWIMs+ACVNHSrFiCOKKmFhhMIKVo6D7LSxBmlHAB0UtfhjR63WLEF+Q0TUTGxYsSMRGEQxYsTDHtUSxYmlhK53LFiYa+IuHSraxMkL3oeRwWLEEGMgWLFiCf/9k=
#with open('file.png', 'w') as f_vid:
# f_vid.write(base64.b64encode(img))
#print video_stream
return ("Done")
@app.route("/delete", methods=["GET", "POST"])
def delete():
newTitle = request.form["newTitle"]
global title_name
#Now set new title name
title_name = newTitle
#open bookEdit
with open('./templates/json/bookEdit.json', 'r') as openBookEdit:
contents = json.load(openBookEdit)
# LOAD THE DATA
books = contents["books"]
found = None
for i in range(len(books)):
if title_name in books[i]:
found = books[i]
books.pop(i)
break
with open('./templates/json/bookEdit.json', 'w') as Book: #
json.dump(contents,Book)
return redirect(url_for('profile'))
@app.route("/test")
def test():
#title_name = "test"
# Opening JSON file FOR HTML EDITING
return render_template("json/"+title_name+".json")# render_template("json/book.json")
@app.route("/displayEdit", methods=["GET"])
def displayEdit():
return render_template("json/bookEdit.json")
@app.route("/bookMode", methods=["GET", "POST"])
def bookMode():
#Revieve the title name and change this global title name and direct it to editor
newTitle = request.form["bookName"]
global title_name
#Now set new title name
title_name = newTitle
return '', 204
@app.route("/editMode", methods=["GET", "POST"])
def editMode():
#Revieve the title name and change this global title name and direct it to editor
newTitle = request.form["newTitle"]
global title_name
#Now set new title name
title_name = newTitle
return redirect(url_for('editor'))
@app.route("/displayLibrary", methods=["GET"])
def displayLibrary():
return render_template("json/bookLibrary.json")
@app.route("/libMode", methods=["GET", "POST"])
def libMode():
#Revieve the title name and change this global title name and direct it to editor
libTitle = request.form["libTitle"]
global title_name
#Now set new title name
title_name = libTitle
#Now open the json file with that title
with open('./templates/json/'+title_name+'.json', 'r') as openBook:
info = json.load(openBook)
# LOAD THE DATA
author_name = info["author_name"]
#Now open library to put new info in
with open('./templates/json/bookLibrary.json', 'r') as LibBook:
data = json.load(LibBook)
#First two lines reset the data
#data = {}
#data["books"] = []
data["books"].append({
"book": {
"auth": author_name,
"title_n": title_name
},
})
#Close and write all info to it
with open('./templates/json/bookLibrary.json', 'w') as Book: #
json.dump(data,Book)
#return(title_name)
#return render_template("KWLibrary.html")
return redirect(url_for('library'))
#Connect to the Site Here:
@app.route("/")
def hello():
return render_template("KWHome.html")
#Have all links here:
@app.route("/home")
def home():
return render_template("KWHome.html")
@app.route("/profile")
def profile():
return render_template("KWProfile.html")
@app.route("/library")
def library():
return render_template("KWLibrary.html")
@app.route("/soon")
def soon():
return render_template("KWSoon.html")
@app.route("/editor")
def editor():
return render_template("KWEditor.html")
#End of new links
@app.route("/edit")
def edit():
return render_template("bookEdit.html");
@app.route("/updateChap", methods=["GET","POST"])
def updateChap():
global title_name;
num = request.form["chapter"]
#Open json file & edit text
#with open('./templates/json/'+title_name+'.json', 'r') as editBook:
# data = json.load(editBook)
#Now if new chapter is added it should be saved
#data = {}
#data["chapters"] = []
#data["chapters"].append({
# "chp" + num: "This is another chapter!"
# })
#with open('./templates/json/' +title_name+ '.json', 'w') as editBook:
# json.dump(data, editBook)
#return render_template("KWProfile.html")
return '', 204
@app.route("/update", methods=["GET","POST"])
def update():
global title_name;
newText = request.form["new_text"]
area = request.form["area"]
#Open json file & edit text
with open('./templates/json/'+title_name+'.json', 'r') as editBook:
data = json.load(editBook)
#Starting
if area == "start":
data["chapters"]["ch1"]= newText
# PUT TEXT IN THEIR PROPER AREAS
if area == "cp":
data["template"]["coverpage"] = newText
if area == "aknow":
data["aknow"] = newText
if area == "main":
data["chapters"]["ch1"] = newText
if area == "toc":
data["toc"] = newText
#Now if new chapter is added it should be saved
with open('./templates/json/' +title_name+ '.json', 'w') as editBook:
json.dump(data, editBook)
#return render_template("KWProfile.html")
return '', 204
#Getting title name back from HTML
@app.route("/book", methods=["GET","POST"])
def book():
global title_name;
# Build JSON Object from form in HTML
title_name = request.form["title_name"] #Get HTML put into new var title_name
author_name = request.form["author_name"]
template = request.form["template"]
#First create book in the editor
#Open to edit
with open('./templates/json/bookEdit.json', 'r') as EditBook:
data = json.load(EditBook)
# LOAD THE DATA
#First two lines reset the data
#data = {}
#data["books"] = []
data["books"].append({
title_name: {
"auth": author_name,
"title_n": title_name
},
})
#Close and write all info to it
with open('./templates/json/bookEdit.json', 'w') as Book: #with open('./templates/json/book.json', 'w') as Book:
json.dump(data,Book)
#Then go onto the creation of the books json
# Check templates first
if template == "default":
templateType = "default"
fontfamily = "Times"
border = "no"
align = "left"
coverpage = "default"
aknow = "yes"
toc = "yes"
if template == "harrypotter":
templateType = "harrypotter"
fontfamily = "Arial"
border = "yes"
align = "left"
coverpage = "harrypotter"
aknow = "yes"
toc = "yes"
if template == "wtp":
templateType = "wtp"
fontfamily = "Impact"
border = "yes"
align = "center"
coverpage = "wtp"
aknow = "yes"
toc = "yes"
if template == "custom":
templateType = "custom"
coverpage = "default"
fontfamily = request.form["fontfamily"]
border = request.form["border"]
align = request.form["align"]
aknow = request.form["aknow"]
toc = request.form["toc"]
# Create new format for JSON Here
newBook = {
"title_name" : title_name,
"author_name" : author_name,
"chapters":
{
"ch1" : "Begin writing your story here...",
},
"template":
{
"type": templateType,
"coverpage": coverpage,
"fontfamily" : fontfamily,
"border": border,
"align": align,
},
}
# Include aknowledgements if they asked
if aknow == 'yes':
newBook["aknow"] = "This is your acknowledgements section"
else:
newBook["aknow"] = "noAknow123"
# Include table of contents if they asked
if toc == 'yes':
newBook["toc"] = "This is your table of contents section"
else:
newBook["toc"] = "noToc123"
#Creates .json file in json folder
#Uses titlename as JSON File name
with open('./templates/json/' + title_name + '.json', 'w') as Book: #with open('./templates/json/book.json', 'w') as Book:
json.dump(newBook,Book)
#return '', 204
#return render_template('KWEditor.html')
return redirect(url_for('editor'))
@app.route("/latex") #, methods=["GET","POST"]
def latex():
global title_name;
# VARIABLES
boldswitch = 0
italicswitch = 0
normalswitch = 1
#title_name = "test" # NEEDS TITLE HERE
#Open json file & edit text
with open('./templates/json/' +title_name+ '.json', 'r') as PDFBook:
data = json.load(PDFBook)
#Start pulling data from JSON file
title_name = data["title_name"]
author_name = data["author_name"]
mainText = data["chapters"]["ch1"]
fontfamily = data["template"]["fontfamily"]
coverpage = data["template"]["coverpage"]
border = data["template"]["border"]
align = data["template"]["align"]
aknow = data["aknow"]
toc = data["toc"]
book = Document(fontenc = 'T1')
##RULE FOR COVERPAGE
#if coverpage == 'yes':
coverpage = coverpage.replace("<p>", "") # remove <p>
coverpage = coverpage.replace("</p>", "") # remove <p>
coverpageRule(book, coverpage)
book.append(NewPage())
####RULE FOR AKNOW
aknow = aknow.replace("<p>", "") # remove <p>
aknow = aknow.replace("</p>", "\n") # at the end return
#Dont need </span> tag
aknow = aknow.replace("</span", "")
###RULE FOR FIXING SPACE BUG THIS GOES AT THE END
aknow = aknow.replace("<", " <") # place spaces so tags can be read
aknow = aknow.replace(">", "> ")
aknow = aknow.replace("&", " &") # place spaces so tags can be read
aknow = aknow.replace(";", "; ")
## Center the Aknow ###
book.append(Command('centering'))
if aknow == "noAknow123":
aknow = ""
book_text = aknow
for word in book_text.split(): #Iterate through each word
### RULE FOR BOLD ###
if word == '<strong>':
boldswitch = 1 #turn switch on
normalswitch = 0
boldFound = boldRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</strong>':
boldswitch = 0
normalswitch = 1
# skip this word here
### RULE FOR ITALICS ###
if word == '<em>':
italicswitch = 1 #turn switch on
normalswitch = 0
italicFound = italicRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</em>':
italicswitch = 0
normalswitch = 1
# skip this word here
## RULE FOR FONT ##
if word == '<span':
normalswitch = 0
#IF normal switch is on continue printing words
if normalswitch == 1:
if word != '</strong>':
if word!= '</em>':
if word!= ' ':
book.append(word + ' ')#print the word and a space word +
## AKNOWLEDGEMENTS GET APPENDED ####
#book.append(aknow)
book.append(NewPage())
##TABLE OF CONTENTS HAS ITS OWN STYLE ###
####RULE FOR AKNOW
toc = toc.replace("<p>", "") # remove <p>
toc = toc.replace("</p>", "\n") # at the end return
#Dont need </span> tag
toc = toc.replace("</span", "")
###RULE FOR FIXING SPACE BUG THIS GOES AT THE END
toc = toc.replace("<", " <") # place spaces so tags can be read
toc = toc.replace(">", "> ")
toc = toc.replace("&", " &") # place spaces so tags can be read
toc = toc.replace(";", "; ")
## Center the Aknow ###
book.append(Command('centering'))
if toc == "noToc123":
toc = ""
book_text = toc
for word in book_text.split(): #Iterate through each word
### RULE FOR BOLD ###
if word == '<strong>':
boldswitch = 1 #turn switch on
normalswitch = 0
boldFound = boldRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</strong>':
boldswitch = 0
normalswitch = 1
# skip this word here
### RULE FOR ITALICS ###
if word == '<em>':
italicswitch = 1 #turn switch on
normalswitch = 0
italicFound = italicRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</em>':
italicswitch = 0
normalswitch = 1
# skip this word here
## RULE FOR FONT ##
if word == '<span':
normalswitch = 0
#IF normal switch is on continue printing words
if normalswitch == 1:
if word != '</strong>':
if word!= '</em>':
if word!= ' ':
book.append(word + ' ')#print the word and a space word +
book.append(NewPage())
book.preamble.append(Command('title', title_name)) # Would need users input here
book.preamble.append(Command('author', author_name)) # Would need users name
book.preamble.append(Command('date', NoEscape(r'\today')))
book.append(NoEscape(r'\maketitle')) #maketitle is an actual command
############################### RULES START HERE ########################################
## REMOVAL RULES BEFORE SPLITTING
##RULE FOR FONT#####
fontRule(book, fontfamily)
####RULE FOR PARAGRAPH
mainText = mainText.replace("<p>", "") # remove <p>
mainText = mainText.replace("</p>", "\n") # at the end return
#Dont need </span> tag
mainText = mainText.replace("</span", "")
###RULE FOR FIXING SPACE BUG THIS GOES AT THE END
mainText = mainText.replace("<", " <") # place spaces so tags can be read
mainText = mainText.replace(">", "> ")
mainText = mainText.replace("&", " &") # place spaces so tags can be read
mainText = mainText.replace(";", "; ")
## RULE FOR ALIGN ###
if align == 'left':
book.append(Command('flushleft'))
if align == 'center':
book.append(Command('centering'))
if align == 'right':
book.append(Command('flushright'))
book_text = mainText
for word in book_text.split(): #Iterate through each word
### RULE FOR BOLD ###
if word == '<strong>':
boldswitch = 1 #turn switch on
normalswitch = 0
boldFound = boldRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</strong>':
boldswitch = 0
normalswitch = 1
# skip this word here
### RULE FOR ITALICS ###
if word == '<em>':
italicswitch = 1 #turn switch on
normalswitch = 0
italicFound = italicRule(book,word,book_text)
#Is you reached the end turn the switch off
if word == '</em>':
italicswitch = 0
normalswitch = 1
# skip this word here
## RULE FOR FONT ##
if word == '<span':
normalswitch = 0
#IF normal switch is on continue printing words
if normalswitch == 1:
if word != '</strong>':
if word!= '</em>':
if word!= ' ':
book.append(word + ' ')#print the word and a space word +
# Iterating words is over <-- Here
# Generate PDF
#book.generate_pdf('./LaTeXFiles/' +title_name+'LaTeX', clean_tex=False)
book.generate_pdf('./static/styles/latex/' +title_name+'LaTeX', clean_tex=False)
tex=book.dumps() # The document as a string in LaTeX syntax
book.generate_tex()
#return "Your Book is called %s" %(title_name)
if border == 'yes':
borderRule(title_name)
#return "Your Book is called %s" %(title_name)
#return render_template('KWLibrary.html')
return '', 204
#return redirect(url_for('editor'))
############# RULES #################
def coverpageRule(book, coverpage):
#doc.packages.append(Package('fullpage'))
#Images and relative paths
scriptDir = os.path.dirname(__file__)
if coverpage == "default":
imageCoverPath = "./static/img/defaultcover.jpg"
if coverpage == "harrypotter":
imageCoverPath = "./static/img/harryPotter.jpg"
if coverpage == "wtp":
imageCoverPath = "./static/img/wtpcover.jpg"
image_covername = os.path.join(scriptDir, imageCoverPath)
#doc.append(Package(image_covername, base='includegraphics', option='scale=0.5'))
#COVER PAGE SECTION
with book.create(Figure(position='h!')) as coverImage: #h!
coverImage.add_image(image_covername, width='300px')
#book.append(NewPage())
return()
def borderRule(title_name):
# This combines the background PDF with the wording (base) PDF
input_pdf='./static/styles/latex/'+title_name+'LaTeX.pdf' #'./LaTeXFiles/'+title_name+'LaTeX.pdf' #'./static/watermark/HarryPBase.pdf'
output_pdf='./static/styles/latex/'+title_name+'LaTeX.pdf' #'./LaTeXFiles/'+title_name+'LaTeX.pdf'#'./LaTeXFiles/'+title_name+'FINALLaTeX.pdf' #This replaces previous file
watermark_pdf='./static/watermark/HarryPBG.pdf'
#Setting up here
watermark = PdfFileReader(watermark_pdf)
watermark_page = watermark.getPage(0)
pdf = PdfFileReader(input_pdf)
pdf_writer = PdfFileWriter()
for page in range(pdf.getNumPages()):
#If its the first page skip it for merging
#But still write it
if page == 0:
pdf_page = pdf.getPage(page)
pdf_writer.addPage(pdf_page)
else:
pdf_page = pdf.getPage(page)
pdf_page.mergePage(watermark_page)
pdf_writer.addPage(pdf_page)
with open(output_pdf, 'wb') as fh:
pdf_writer.write(fh)
return()
def fontRule(book, fontfamily):
##RULE FOR FONT#####
# IMPACT
if fontfamily == 'Impact':
book.packages.append(Package('cyklop')) #asciifamily
book.append(NoEscape(r'\normalfont'))
# ARIAL
if fontfamily == 'Arial':
book.append(NoEscape(r'\sffamily')) #Sansserrif
# TIMES NEW ROMAN
if fontfamily == 'Times':
book.append(NoEscape(r'\rmfamily'))
# If its empty default to times new roman
if fontfamily == '':
book.append(NoEscape(r'\rmfamily'))
def boldRule(book,word,book_text):
#bold rules:
startbold = "<strong>"
endbold = "</strong>"
boldWord = book_text[book_text.find(startbold) + len(startbold):book_text.find(endbold)] # middle word
book.append(bold(boldWord))
return()
def italicRule(book,word,book_text):
#italic rules:
startitalic = "<em>"
enditalic = "</em>"
italicWord = book_text[book_text.find(startitalic) + len(startitalic):book_text.find(enditalic)] # middle word
book.append(italic(italicWord))
return()
###################################################################################################################
@app.route("/HPDemo")
def testing():
#import pylatex.config as cf
#Images and relative paths
scriptDir = os.path.dirname(__file__)
imageCoverPath = "./static/img/harryPotter.jpg" #harryPotter.jpg
imageBabyPath = "./static/img/baby.jpg"
image_covername = os.path.join(scriptDir, imageCoverPath)
image_baby = os.path.join(scriptDir, imageBabyPath)
book = Document('Basic', inputenc = 'utf8x', fontenc = 'T1')#textcomp = None lmodern = False,
#COVER PAGE SECTION
with book.create(Figure(position='h!')) as coverImage:
coverImage.add_image(image_covername, width='300px')
book.append(NewPage())
##### TEST FOR CUSTOM / PRETTY FONTS ############
book.packages.append(Package('ascii')) #asciifamily
book.append(NoEscape(r'\asciifamily'))
#NB This adds controls which are in LATEX to PYLATEX very handy
#book.append(NoEscape(r'\ttfamily')) #Teletype font
#book.append(NoEscape(r'\sffamily')) #Sansserrif
#book.append(NoEscape(r'\rmfamily')) #Roman font AKA Normal
#book.append(NoEscape(r'\scshape')) # Small Capitol
book.append(Command('centering'))
book.append(HugeText(bold("HARRY POTTER \n")))
book.append(LargeText(bold("And the Philosopher's Stone")))
book.append(NewPage())
# ALSO BY SECTION
with book.create(Section('ALSO BY J.K ROWLING',numbering=False)):
with book.create(Subsection('Harry Potter and the Sorcerers Stone',numbering=False)):
book.append("Year One at Hogwarts")
with book.create(Subsection('Harry Potter and the Chamber of Secrets',numbering=False)):
book.append("Year Two at Hogwarts")
with book.create(Subsection('Harry Potter and the Prisoner of Azkaban',numbering=False)):
book.append("Year Three at Hogwarts")
with book.create(Subsection('Harry Potter and the Goblet of Fire',numbering=False)):
book.append("Year Four at Hogwarts")
with book.create(Subsection('Harry Potter and the Oder of the Phoenix',numbering=False)):
book.append("Year Five at Hogwarts")
with book.create(Subsection('Harry Potter and the Half-Blood Prince',numbering=False)):
book.append("Year Six at Hogwarts")
with book.create(Subsection('Harry Potter and the Deathly Hallows',numbering=False)):
book.append("Year Seven at Hogwarts")
book.append(NewPage())
#AKNOWLEDGEMENTS SECTION
book.append(LargeText(bold("For Sean D. F Harris \n \n")))
book.append(LargeText(bold("Getaway Driver and Foul-Weather Friend \n")))
book.append(SmallText('''Text copywrite @ 1999 by J.K Rowling.
Donec pellentesque libero id tempor aliquam. Maecenas a diam at metus varius
rutrum vel in nisl. Maecenas a est lorem. Vivamus tristique nec eros ac
hendrerit. Vivamus imperdiet justo id lobortis luctus. Sed facilisis ipsum ut
tellus pellentesque tincidunt. Mauris libero lectus, maximus at mattis ut,
venenatis eget diam. Fusce in leo at erat varius laoreet. Mauris non ipsum
pretium, convallis purus vel, pulvinar leo. Aliquam lacinia lorem dapibus
tortor imperdiet, quis consequat diam mollis.'''))
book.append(NewPage())
# TABLE OF CONTENTS SECTION
book.append(Command('centering'))
with book.create(Section('CONTENTS Numbering',numbering=False)):
with book.create(Description()) as desc:
book.append(Command('centering'))
desc.add_item("ONE", "The first item")
desc.add_item("TWO", "The second item")
desc.add_item("THREE", NoEscape("The third etc \\ldots"))
# TRY HAVE SECTION SUB SECTION ETC
book.append(Command('centering'))
with book.create(Section('CONTENTS Sections',numbering=False)):
with book.create(Subsection('ONE',numbering=False)):
book.append("The first item")
with book.create(Subsection('TWO',numbering=False)):
book.append("The second item")
with book.create(Subsection('THREE',numbering=False)):
book.append("The third etc \\ldots")
book.append(NewPage())
# Create center header
header = PageStyle("header")
with header.create(Head("C")): # C for Centre
header.append("CHAPTER ONE")
# Create center footer with the page numbers
with header.create(Foot("C")):
#header.append(simple_page_number())
book.preamble.append(header)
book.change_document_style("header")
# Add image of baby
with book.create(Figure(position='h!')) as image:
image.add_image(image_baby, width='200px')
#book.append(Command('centering'))
with book.create(Section('THE BOY WHO LIVED',numbering=False)):
book.append(Command('flushleft'))
book.append(''' Not for the first time, an argument had broken out over breakfast at number four, Privet Drive.
Mr. Vernon Dursley had been woken in the early hours of the morning by a loud, hooting noise from his nephew
Harry’s room.“Third time this week!” he roared across the table. “If you can’t control that owl, it’ll have to go!”
Harry tried, yet again, to explain.“She’s bored,” he said. “She’s used to flying around outside.
If I could just let her out at night —” “Do I look stupid?” snarled Uncle Vernon, a bit of fried egg dangling
from his bushy mustache. “I know what’ll happen if that owl’s let out.” He exchanged dark looks with his wife, Petunia.
Harry tried to argue back but his words were drowned by a long, loud belch from the Dursleys’ son, Dudley.
“I want more bacon.” “There’s more in the frying pan, sweetums,” said Aunt Petunia,
turning misty eyes on her massive son. “We must build you up while we’ve got the chance. . . .
I don’t like the sound of that school food. . . .” “Nonsense, Petunia, I never went hungry when I was at Smeltings,”
said Uncle Vernon heartily. “Dudley gets enough, don’t you, son?”
Dudley, who was so large his bottom drooped over either side of the kitchen chair, grinned and turned to Harry.
“Pass the frying pan.” “You’ve forgotten the magic word,” said Harry irritably.
The effect of this simple sentence on the rest of the family was incredible: Dudley gasped and fell off his chair
with a crash that shook the whole kitchen; Mrs. Dursley gave a small scream and clapped her hands to her mouth;
Mr. Dursley jumped to his feet, veins throbbing in his temples. “I meant ‘please’!” said Harry quickly.
“I didn’t mean —” “WHAT HAVE I TOLD YOU,” thundered his uncle, spraying spit over the table,
“ABOUT SAYING THE ‘M’ WORD IN OUR HOUSE?” “But I —” “HOW DARE YOU THREATEN DUDLEY!” roared Uncle Vernon,
pounding the table with his fist. “I just —” “I WARNED YOU! I WILL NOT TOLERATE MENTION OF YOUR ABNORMALITY
UNDER THIS ROOF!” Harry stared from his purple-faced uncle to his pale
aunt, who was trying to heave Dudley to his feet.
Dudley hitched up his trousers, which were slipping down his fat bottom. “Why’re you staring at the hedge?”
he said suspiciously. “I’m trying to decide what would be the best spell to set it on fire,” said Harry.
Dudley stumbled backward at once, a look of panic on his fat face. “You c-can’t — Dad told you you’re
not to do m-magic — he said he’ll chuck you out of the house — and you haven’t got anywhere else to
go — you haven’t got any friends to take you —” “Jiggery pokery!” said Harry in a fierce voice.
“Hocus pocus — squiggly wiggly —” “MUUUUUUM!” howled Dudley, tripping over his feet as he dashed
back toward the house. “MUUUUM! He’s doing you know what!” Harry paid dearly for his moment of fun.
As neither Dudley nor the hedge was in any way hurt, Aunt Petunia knew he hadn’t really done magic,
but he still had to duck as she aimed a heavy blow at his head with the soapy frying pan.
Then she gave him work to do, with the promise he wouldn’t eat again until he’d finished.
While Dudley lolled around watching and eating ice cream, Harry cleaned the windows,
washed the car, mowed the lawn, trimmed the flowerbeds, pruned and watered the roses,
and repainted the garden bench. The sun blazed overhead, burning the back of his neck.
Harry knew he shouldn’t have risen to Dudley’s bait, but Dudley had said the very thing
Harry had been thinking himself . . . maybe he didn’t have any friends at Hogwarts. . . .
Wish they could see famous Harry Potter now, he thought savagely as he spread manure on the flower beds,
his back aching, sweat running down his face. It was half past seven in the evening when at last, exhausted,
he heard Aunt Petunia calling him. “Get in here! And walk on the newspaper!” Harry moved gladly
into the shade of the gleaming kitchen. On top of the fridge stood tonight’s pudding: a huge mound of
whipped cream and sugared violets. A loin of roast pork was sizzling in the oven. “Eat quickly!
The Masons will be here soon!” snapped Aunt Petunia, pointing to two slices of bread and a lump
of cheese on the kitchen table. She was already wearing a salmon-pink cocktail dress. Harry
washed his hands and bolted down his pitiful supper. The moment he had finished, Aunt Petunia
whisked away his plate. “Upstairs! Hurry!”
As he passed the door to the living room, Harry caught a glimpse of Uncle Vernon and Dudley in bow ties
and dinner jackets. He had only just reached the upstairs landing when the doorbell rang and
Uncle Vernon’s furious face appeared at the foot of the stairs. “Remember, boy — one sound —”
Harry crossed to his bedroom on tiptoe, slipped inside, closed the door, and turned to collapse on his bed.
The trouble was, there was already someone sitting on it.''')
book.generate_pdf('./static/watermark/HarryPBase',clean_tex=False) #clean_tex=False src="/static/img/hp.jpg"
tex=book.dumps() # The document as a string in LaTeX syntax
book.generate_tex()
# This combines the background PDF with the wording (base) PDF
input_pdf='./static/watermark/HarryPBase.pdf'
output_pdf='./LaTeXFiles/HarryPotterDEMO.pdf'
watermark_pdf='./static/watermark/HarryPBG.pdf'
watermark = PdfFileReader(watermark_pdf)
watermark_page = watermark.getPage(0)
pdf = PdfFileReader(input_pdf)
pdf_writer = PdfFileWriter()
for page in range(pdf.getNumPages()):
pdf_page = pdf.getPage(page)
pdf_page.mergePage(watermark_page)
pdf_writer.addPage(pdf_page)
with open(output_pdf, 'wb') as fh:
pdf_writer.write(fh)
return render_template('KWLibrary.html')