-
Notifications
You must be signed in to change notification settings - Fork 1
/
readmetas.py3
70 lines (60 loc) · 1.52 KB
/
readmetas.py3
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
#!/usr/bin/python
# -*- coding: utf8 -*-
# coding=UTF-8
import os
import re
import sys
import daba.formats1
fileINname= str(sys.argv[1])
if fileINname.endswith(".dis.html"): fileDISname=fileINname
else: fileDISname=fileINname+".dis.html"
if os.path.exists(fileDISname) :
print("processing ",fileDISname)
else:
sys.exit("\n\033[1mno file named "+fileDISname+"\033[0m\n")
freader = daba.formats1.HtmlReader(fileDISname)
metadata = freader.metadata
#print(metadata)
#print("--------------")
metas={}
items=[]
authors=False
for x,y in metadata.items():
item,subitem=x.split(":")
if item in items:
if item=="author" and authors:
vy=y.split("|")
authindex=0
for v in vy:
authindex+=1
metas[item][authindex][subitem]=v
else:
metas[item][subitem]=y
else:
items.append(item)
if item=="author":
if "|" in y:
vy=y.split("|")
authors=True
authindex=0
for v in vy:
authindex+=1
if authindex==1:
metas[item]={authindex: {subitem:v}}
else : metas[item][authindex]={subitem:v}
else:
metas[item]={subitem:y}
#print("\n",metas,"\n")
else:
metas[item]={subitem:y}
#print(metas)
#print("--------------")
print("\033[42;30;1mMETA \033[0m\n")
for x,y in sorted(metas.items()):
print(x)
for w,z in sorted(y.items()):
if x=="author" and authors:
print("\t",w,":")
for wn,zn in sorted(z.items()):
print("\t\t",wn,":\t",zn)
else: print("\t",w,":\t",z)