-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileCls.py
More file actions
executable file
·657 lines (601 loc) · 20.5 KB
/
fileCls.py
File metadata and controls
executable file
·657 lines (601 loc) · 20.5 KB
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
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
import os
import codecs
import json
from urllib import request as urlRequest
import pdfplumber
import listFct
import textFct
import htmlFct
from fileLocal import *
from fileTemplate import *
from htmlFromText import toHtml
import loggerFct as log
dateFormatFull = '%Y/%m/%d %H:%M:%S'
dateFormatDay = '%Y-%m-%d'
dateFormatHour = dateFormatDay + '-%H-%M'
# ------ fonctions basiques ------
def decodeFileContent (textBrut):
tmpByte = textBrut.read()
encodingList = ('utf-8', 'ascii', 'ISO-8859-1', 'ISO8859-1')
text =""
for encoding in encodingList:
try: text = codecs.decode (tmpByte, encoding=encoding)
except UnicodeDecodeError: pass
else: break
if not text:
for encoding in encodingList:
try: text = codecs.decode (tmpByte, encoding=encoding, errors='ignore')
except UnicodeDecodeError: pass
else: break
textBrut.close()
return text
def fromFile (fileName):
if not os.path.exists (fileName):
print ("ce fichier n'existe pas:", fileName)
return ""
else:
textBrut = open (fileName, 'rb')
text = decodeFileContent (textBrut)
return text
def toFile (fileName, text, mode='w'):
if not text:
print ('rien a ecrire pour:', fileName)
return
d=1+ fileName.rfind (os.sep)
title = fileName[d:]
chars = '/\\\t\n><';
toWrite = True
for c in chars:
if c in title: toWrite = False
if toWrite:
if mode == 'a': text = '\n'+ text
textBrut = open (fileName, mode +'b')
textBrut.write (text.encode ('utf-8'))
textBrut.close()
else: print ('le titre du fichier est mal formé', title)
def fromUrl (url, params=None):
text =""
try:
myRequest = None
if params:
paramsUrl = ul.parse.urlencode (params).encode ('utf-8')
myRequest = urlRequest.Request (url, method='POST', headers={ 'User-Agent': 'Mozilla/5.0' })
else: myRequest = urlRequest.Request (url, headers={ 'User-Agent': 'Mozilla/5.0' })
textBrut = urlRequest.urlopen (myRequest)
text = decodeFileContent (textBrut)
except Exception as e:
text =""
print (e)
if not text:
try: urlRequest.urlretrieve (url, 'tmp.txt')
except Exception as e: print (e)
else:
textBrut = open ('tmp.txt', 'rb')
text = decodeFileContent (textBrut)
os.remove ('tmp.txt')
else: print ('la récupération à échoué, impossible de récupérer les données pour\n' + url)
return text
def comparerText (textA, textB):
textA = textA.replace ('\t'," ")
textA = textFct.cleanBasic (textA)
textB = textB.replace ('\t'," ")
textB = textFct.cleanBasic (textB)
if textA == textB: return 'c les textes sont identiques'
listA = textA.split ('\n')
listB = textB.split ('\n')
listCommon = listFct.comparer (listA, listB)
if listCommon[0][1] == 'c': return 'c les textes sont différents'
textCommon =""
for line in listCommon:
textCommon = textCommon +'\n'+ line[1] +'\t'+ line[0]
return textCommon[1:]
class File():
def __init__ (self, file =None):
self.path =""
self.title =""
self.text =""
if file:
self.path = file
self.fromPath()
def comparer (self, fileB):
# self et fileB sont ouverts
title = 'b/comparer %s et %s.txt' %( self.title, fileB.title)
fileCommon = File (title)
if (self.path[-4:] == '.css' and fileB.path[-4:] == '.css') or (self.path[-3:] == '.js' and fileB.path[-3:] == '.js'):
toClean = '{}();"\''
for item in toClean:
self.text = self.text.replace (item,"")
fileB.text = fileB.text.replace (item,"")
fileCommon.text = comparerText (self.text, fileB.text)
if fileCommon.text[0] != 'c': fileCommon.write()
else: print (fileCommon.text)
def fromPath (self):
if '\t' in self.path: return
self.path = shortcut (self.path)
# if os.sep not in self.path or '.' not in self.path:
if '.' not in self.path:
print ('fichier malformé:\n' + self.path)
return
elif self.path.rfind (os.sep) > self.path.rfind ('.'):
# print ('fichier malformé:\n' + self.path)
return
posS = self.path.rfind (os.sep) +1
posE = self.path.rfind ('.')
self.title = self.path [posS:posE]
self.path = self.path [:posS] +'\t'+ self.path [posE:]
# self.path = self.path.replace (self.title, '\t')
def toPath (self):
if '\t' in self.path:
self.path = self.path.replace ('\t', self.title)
self.path = shortcut (self.path)
def remove (self):
self.toPath()
if os.path.exists (self.path): os.remove (self.path)
def read (self):
self.toPath()
if not os.path.exists (self.path): return
self.text = fromFile (self.path)
self.fromPath()
def write (self, mode='w'):
self.toPath()
toFile (self.path, self.text, mode)
def copy (self):
newFile = File (self.path)
newFile.title = self.title
newFile.type = self.type
return newFile
def toMarkdown (self):
self.text = textFct.toMarkdown (self.text)
self.path = self.path.replace ('.txt', '.md')
def readJson (self):
if not self.text: self.read()
self.replace ('\n')
self.replace ('\t')
self.replace (',]', ']')
d= self.text.find ('{')
f= self.text.rfind (';')
self.text = self.text[d:f]
jsonData = json.loads (self.text)
return jsonData
def divide (self):
self.fromPath()
self.text = textFct.shape (self.text)
if len (self.text) < 420000: self.write()
else:
sep = '\n'
if '== ' in self.text: sep = '== '
elif '** ' in self.text: sep = '** '
elif '<h1>' in self.text and self.text.count ('<h1>') >1: sep = '<h1>'
elif '<h2>' in self.text: sep = '<h2>'
newFile = self.copy()
counter =1
newFile.title = self.title +' %02d' % counter
lines = self.text.split (sep)
newFile.text = lines.pop (0)
for line in lines:
if len (newFile.text) >300000:
newFile.write()
counter +=1
newFile = self.copy()
newFile.title = self.title +' %02d' % counter
newFile.text = newFile.text + sep + line
newFile.write()
def shortcut (self):
self.path = shortcut (self.path)
def replace (self, wordOld, wordNew=""):
self.text = self.text.replace (wordOld, wordNew)
def __str__ (self):
strShow = 'Titre: %s' % self.title
if self.text: strShow += '.\t%d caractères' % len (self.text)
return strShow
def __lt__ (self, newFile):
""" nécessaire pour trier les listes """
self.toPath()
newFile.toPath()
return self.path < newFile.path
def __setitem__ (self, pos, item):
lenList = len (self.text)
if type (pos) == int:
itemStr = str (item)
if len (itemStr) ==1:
while pos <0: pos += lenList
if pos < lenList: self.text[pos] = str (item)
else: self.text = self.text + str (item)
elif type (pos) == slice:
posIndex = pos.indices (lenList)
rangeList = self.range (posIndex[0], posIndex[1], posIndex[2])
if type (item) in (tuple, list, str) and len (item) >= len (rangeList):
i=0
for l in rangeList:
self.list[l] = str (item[i])
i+=1
def __getitem__ (self, pos):
lenList = len (self.text)
if type (pos) == int:
while pos <0: pos += lenList
while pos >= lenList: pos -= lenList
return self.text [pos]
elif type (pos) == slice:
posIndex = pos.indices (lenList)
rangeList = self.range (posIndex[0], posIndex[1], posIndex[2])
newList =""
for l in rangeList: newList = newList + self.text[l]
return newList
else: return None
def __len__(self):
return len (self.text)
def find (self, word, posStart=0):
pos =-1
if word in self.text[posStart:]: pos = self.text.find (word, posStart)
elif "'" in word:
word = word.replace ("'",'"')
if word in self.text[posStart:]: pos = self.text.find (word, posStart)
elif '"' in word:
word = word.replace ('"',"'")
if word in self.text[posStart:]: pos = self.text.find (word, posStart)
if pos >-1: pos += posStart
return pos
def rfind (self, word, posEnd=0):
if posEnd <1: posEnd += len (self.text)
pos =-1
if word in self.text[:posEnd]: pos = self.text[:posEnd].rfind (word)
elif "'" in word:
word = word.replace ("'",'"')
if word in self.text[:posEnd]: pos = self.text[:posEnd].rfind (word)
elif '"' in word:
word = word.replace ('"',"'")
if word in self.text[:posEnd]: pos = self.text[:posEnd].rfind (word)
return pos
def toList (self, sep='\n'):
if sep not in self.text: return []
textTmp = self.replace (sep + sep, sep)
while sep + sep in textTmp: textTmp = textTmp.replace (sep + sep, sep)
textList = self.split (textTmp)
return textList
def fromList (self, textList, sep='\n'):
if textList: self.text = sep.join (textList)
def test (self):
self.path = 'b/test-file.txt'
print ('fromPath\t', self.path)
self.fromPath()
self.text = """nekg,ze,fmalf,al,f
fkz,fzkl,fam; v adbazjkbdafaef"""
print ('affichage\t', self)
print ('écriture')
self.write()
self.read()
print ('lecture\t', self.text)
self.title = 'coco'
self.toPath()
print ('modifier le titre\t', self.path)
self.text = textFct.shape (self.text, 'reset')
print (self.text[:200])
self.write()
class FileCss (File):
def __init__ (self, file =None):
File.__init__ (self, file)
self.blocs =[]
def toSelection (self, tagList=[]):
text =""
for bloc in self.blocs:
if '*' in bloc[0] or ':root' in bloc[0] or 'body' in bloc[0] or 'html' in bloc[0]:
text = text + bloc[0] +' { '+ bloc[1].replace (':', ': ') +'}\n'
for tag in tagList:
for bloc in self.blocs:
if tag in bloc[0] and bloc[0] not in text:
text = text + bloc[0] +' { '+ bloc[1].replace (':', ': ') +'}\n'
text = text.replace (';', '; ')
return text
def read (self):
File.read (self)
self.text = self.replace ('\n'," ")
self.text = self.replace ('\t'," ")
self.text = self.replace ('\r'," ")
self.cleanForStandarding()
# supprimer les commentaires
if '/*' in self.text:
textList = self.text.split ('/*')
rangeList = range (1, len (textList))
for c in rangeList:
f=2+ textList[c].find ('*/')
textList[c] = textList[c][f:]
self.text = "".join (textList)
self.cleanForStandarding()
# repérer les média queries
if '@media' in self.text:
textList = self.text.split ('@media')
rangeList = range (1, len (textList))
for c in rangeList:
d= textList[c].find ('}')
nOpening = textList[c][:d].count ('{')
nClosing =1
while nOpening > nClosing:
d= textList[c].find ('}',d+1)
nOpening = textList[c][:d].count ('{')
nClosing =1+ textList[c][:d].count ('}')
text = textList[c][:d].replace ('}',']]')
text = text.replace ('{','[[')
text = text.replace ('[[','{',1)
textList[c] = text + textList[c][d:]
self.text = '@media'.join (textList)
self.cleanForStandarding()
# créer les blocks
textList = self.text.split ('}')
trash = textList.pop (-1)
rangeList = range (len (textList))
for c in rangeList:
textList[c] = textList[c].strip()
textList[c] = textList[c].split ('{')
if 2!= len (textList[c]): log.message (textList[c])
textList[c][0] = textList[c][0].strip()
textList[c][1] = textList[c][1].strip()
textList[c][1] = textList[c][1].replace ('[[','{ ')
textList[c][1] = textList[c][1].replace (']]','}')
self.blocs.append (( textList[c][0], textList[c][1] ))
def cleanForStandarding (self):
while " " in self.text: self.text = self.replace (" "," ")
marquers ='{}:;'
for mark in marquers:
self.text = self.replace (" "+ mark, mark)
self.text = self.replace (mark +" ", mark)
class Article (File):
# classe pour les fichiers txt et html
def __init__ (self, file =None):
File.__init__ (self, file)
self.author =""
self.subject =""
self.link =""
self.type =""
self.meta ={}
if file: self.fromPath()
def explode (self):
# découper une trop longue fanfic en morceaux
if len (self.text) > 450000:
# créer l'article temporaire
idFile =1
idText =0
ficNew = Article()
ficNew.subject = self.subject
ficNew.link = self.link
ficNew.author = self.author
ficNew.type = self.type
ficNew.path = self.path
ficNew.meta = self.meta
ficNew.text =""
# récupérer le séparateur selon le type de l'article
sep = ""
if '<h1>' in self.text: sep = '<h1>'
elif self.type == 'txt':
self.text = textFct.clean (self.text)
if '** ' in self.text: sep = '** '
elif '== ' in self.text: sep = '== '
if sep:
ficList = self.text.split (sep)
if not ficList[0]: trash = ficList.pop (0)
ficRange = listFct.rangeList (ficList)
for f in ficRange:
ficNew.text = ficNew.text + sep + ficList[f]
if len (ficNew.text) >= 300000:
idText =f
ficNew.path = self.path
ficNew.title = self.title +' '+ str (idFile)
ficNew.write()
ficNew.text =""
idFile = idFile +1
idText = idText +1
self.text = sep.join (ficList[idText:])
self.text = sep + self.text
self.title = self.title +' '+ str (idFile)
self.write()
def fromPath (self):
File.fromPath (self)
if self.path[-3:] == 'txt': self.type = 'txt'
elif self.path[-5:] == 'xhtml': self.type = 'xhtml'
elif self.path[-4:] == 'html': self.type = 'html'
def write (self):
self.title = self.title.lower()
meta = self.metaToText()
self.text = textFct.cleanText (self.text)
self.text = textFct.shape (self.text, 'reset upper')
self.text = templateText % (self.text, self.subject, self.author, self.link, meta)
File.write (self, 'w')
def read (self):
File.read (self)
self.getMetas()
def fromFile (self, fileObj):
self.title = fileObj.title
self.path = fileObj.path
self.text = fileObj.text
self.subject = 'o'
self.author = 'o'
self.link = 'o'
if '\n==\n' in self.text and '\nSujet: ' in self.text: self.getMetas()
def getMetas (self):
metadata =[]
self.text = textFct.cleanText (self.text)
if self.type == 'txt' and '\n==\n' in self.text:
self.text = textFct.shape (self.text)
self.text = self.text.strip()
d= self.text.rfind ('\n==')
metaText = self.text[d:].lower()
# metaText = metaText.replace (':\t',': ')
metaText = metaText +'\n'
self.text = self.text[:d]
metadata = textFct.fromModel (metaText, templateTextMeta)
self.subject = metadata[0]
self.author = metadata[1]
self.link = metadata[2]
if len (metadata) >3: self.metaFromText (metadata[3])
"""
metaList = metadata[3].split ('\n')
for meta in metaList:
d= meta.find (':')
self.meta[meta[:d]] = meta[d+2:]
"""
def metaFromText (self, text):
if 'style:\n' in text:
text = text +'\n'
d= text.find ('style:\n')
f=1+ text.rfind ('}\n')
if 'script:\n' in text[:f]:
f= text.rfind ('script:\n')
f=1+ text[:f].rfind ('}\n')
self.meta['style'] = text[d+7:f]
text = text[:d] + text[f:].strip()
if 'script:\n' in text:
text = text +'\n'
d= text.find ('script:\n')
e=1+ text.rfind ('}\n')
f=1+ text.rfind (';\n')
if e>f: f=e
self.meta['script'] = text[d+8:f]
text = text[:d] + text[f:].strip()
textList = text.split ('\n')
for line in textList:
d= line.find (': ')
self.meta [line[:d]] = line[d+2:]
def metaToText (self):
metaTemplate = '%s: %s\n'
text =""
for meta in self.meta: text = text + metaTemplate % (meta, self.meta[meta])
return text
def toDico (self):
dico ={}
dico['title'] = self.title
dico['subject'] = self.subject
dico['author'] = self.author
self.toPath()
dico['path'] = self.path
return dico
def copy (self):
article = Article (self.path)
article.subject = self.subject
article.title = self.title
article.type = self.type
article.link = self.link
article.author = self.author
self.meta = self.meta
return article
def fromPdfTxt (self):
# le fichier d'origine est un txt contenant du texte mal formaté récupéré par copié-collé d'un pdf
# gérer les espaces blancs
while " " in self.text: self.replace (" "," ")
self.replace ('\n \n', '\n')
while '\n\n' in self.text: self.replace ('\n\n', '\n')
self.replace ("\n ", " ")
self.replace (" \n", " ")
# gérer les coupures de mots
self.replace ('-\n')
self.replace ('- \n')
# gérer les lettres
alphabet = 'aàbc\xe7deéêèëfghiîïjklmnoôpqrstuùvwxyz,;/\\'
for l in alphabet:
self.replace (l+'\n', l+" ")
self.replace ('\n'+l, " "+l)
points = '.!?;,/\\'
for p in points: self.replace ('\n'+p, " "+p)
self.cleanBasic()
def fromPdf (self, getImg=True):
# le fichier d'origine est un pdf, path.pdf. https://pypi.org/project/pdfplumber/#command-line-interface
self.subject = 'o'
self.author = 'o'
self.toPath()
self.link = self.path
filePdf = pdfplumber.open (self.path)
# pour chaque page, récupérer le texte
self.path = self.path.replace ('.pdf', '.txt')
numbers = '0123456789'
for page in filePdf.pages:
self.text = self.text +'\n/ img / page %02d\n' % page.page_number
textTmp = page.extract_text()
if '\n' in textTmp:
f=1+ textTmp.rfind ('\n')
if (len (textTmp) -f) <4 and textTmp[-1] in numbers and textTmp[f] in numbers: textTmp = textTmp[:f-1]
self.text = self.text + textTmp
# nettoyer le texte
self.text = self.replace ('-\n', "")
self.text = textFct.cleanText (self.text)
midleChars = '?!:;,. -_abcdefghijklmnopqrstuvwxyz'
for char in midleChars: self.text = self.replace ('\n'+ char, " "+ char)
startChars = 'ABCDEFGIJKLMNOPQRSTUVWXYZ0123456789/\\-_' + numbers
endChars = '?!:./\\' + numbers
for char in startChars: self.text = self.replace ('\n'+ char, '\t'+ char)
for char in endChars: self.text = self.replace (char +'\n', char +'\t')
self.text = self.replace ('\n', " ")
for char in startChars: self.text = self.replace ('\t'+ char, '\n'+ char)
for char in endChars: self.text = self.replace (char +'\t', char +'\n')
# pour chaque page, récupérer les images
if getImg: self.fromPdfImg (filePdf.pages)
else: self.text = self.replace ('/ img / ', '== ')
# récupérer d'éventuelles métadonnées
metaKeys = filePdf.metadata.keys()
if 'subject' in metaKeys: self.subject = filePdf.metadata['subject']
elif 'Subject' in metaKeys: self.subject = filePdf.metadata['Subject']
elif 'sujet' in metaKeys: self.subject = filePdf.metadata['sujet']
elif 'Sujet' in metaKeys: self.subject = filePdf.metadata['Sujet']
if 'author' in metaKeys: self.author = filePdf.metadata['author']
elif 'Author' in metaKeys: self.author = filePdf.metadata['Author']
elif 'auteur' in metaKeys: self.author = filePdf.metadata['auteur']
elif 'Auteur' in metaKeys: self.author = filePdf.metadata['Auteur']
if 'ModDate' in metaKeys: self.meta['date'] = filePdf.metadata['ModDate']
elif 'ModificationDate' in metaKeys: self.meta['date'] = filePdf.metadata['ModificationDate']
elif 'CreationDate' in metaKeys: self.meta['date'] = filePdf.metadata['CreationDate']
def fromPdfImg (self, pages):
# créer un dossier pour contenir les éventuelles images. pages = filePdf.pages
self.fromPath()
i= self.path.find ('\t')
imgPathShort = self.title + os.sep
imgPath = self.path[:i] + imgPathShort
if not os.path.exists (imgPath): os.mkdir (imgPath)
images =[]
# pour chaque page, récupérer les images
for page in pages:
images.append ("")
for img in page.images:
bbox = [img['x0'], img['y0'], img['x1'], img['y1']]
# bbox = [img['x0'], page.cropbox[3] - img['y1'], img['x1'], page.cropbox[3] - img['y0']]
if bbox[0] < page.cropbox[0]: bbox[0] = page.cropbox[0]
if bbox[1] < page.cropbox[1]: bbox[1] = page.cropbox[1]
if bbox[2] > page.cropbox[2]: bbox[2] = page.cropbox[2]
if bbox[3] > page.cropbox[3]: bbox[3] = page.cropbox[3]
if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]: continue
imgPage = page.crop (bbox=bbox)
imgObj = imgPage.to_image (resolution=100)
imgNameShort = "%s%02d %s.png" % (imgPathShort, img['page_number'], img['name'])
imgName = "%s%02d %s.png" % (imgPath, img['page_number'], img['name'])
imgObj.save (imgName)
images[-1] = images[-1] + imgNameShort +'\n'
# rajouter les images dans le texte
textList = self.text.split ('/ img / ')
textRange = range (1, len (textList))
for t in textRange: textList[t] = textList[t] + images[t-1]
self.text = '== '.join (textList)
def __str__ (self):
strShow = 'Titre: %s\tSujet: %s\tAuteur: %s' % (self.title, self.subject, self.author)
if self.text: strShow += '\n\t%d caractères' % len (self.text)
return strShow
def __lt__ (self, newFile):
""" nécessaire pour trier les listes """
struct = '%st%st%s'
return struct % (self.subject, self.author, self.title) < struct % (newFile.subject, newFile.author, newFile.title)
def test (self):
self.author = 'moi'
self.subject = 'random'
self.link = 'http://www.test.fr/'
self.text = """nekg,ze,fmalf,al,f
fkz,fzkl,fam; v adbazjkbdafaef"""
print ('affichage\t', self)
self.fromPath()
print ('fromPath\t', self.path)
print ('écriture')
self.write()
self.read()
print ('lecture\t', self.text[:200])
print ('conversion en html')
self.path = self.path.replace ('.txt', '.html')
self.text = htmlFct.toHtml (self.text)
self.type = 'html'
print ('text html\t', self.text)
self.write()