-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconstruct.html.py
135 lines (99 loc) · 3.09 KB
/
reconstruct.html.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
#from PyPDF2 import PdfFileWriter, PdfFileReader
import zipfile
from fpdf import FPDF
from html import HTML
import re
import os
import argparse
parser=argparse.ArgumentParser("Provide the zipped whatsapp file and the name of the two participatnts")
parser.add_argument('--zip',help="zipped whatapp chat archive")
parser.add_argument('-p1',help="first person")
parser.add_argument('-p2',help="second person")
args=parser.parse_args()
fn=args[1]
part1=args[2]
part3=args[3]
exit()
### set up the pdf
pdf=FPDF()
pdf.add_page()
pdf.set_xy(0,0)
pdf.set_font('Times','',10.0)
effective_page_width = pdf.w - 2*pdf.l_margin
h=HTML()
fn="Sema_20180929.zip"
zipchat = zipfile.ZipFile(fn, 'r')
#zipchat.printdir()
#chat=zipchat.read("_chat.txt")
chat=zipchat.open("_chat.txt")
#print chat
#exit()
#print chat
part1="Sema"
part2="Lawrence"
#pdf.image("00006181-PHOTO-2018-09-11-05-28-18.jpg",h=20)
n=20
cur_ds=0 ### current datastamp
for line in chat.readlines():
#print(line)
#x=raw_input("Press Enter to continue...")
#continue
m=re.search("(\[.*?\]) (\S+): (.*)",line)
if m:
ts=m.group(1)
#print ts
ds=re.search("(\d+\/\d+\/\d+)",ts).group(1)
#print ds
#raw_input("Press Enter to continue...")
if ds!=cur_ds:
#print "new ts is",ts
if cur_ds != 0:
pdf.add_page()
print ds
align="C"
pdf.set_font('Times','B',20.0)
pdf.set_text_color(0,0,0)
pdf.cell(h=5,align=align,w=0,txt=ds, border=0)
pdf.set_font('Times','',10.0)
pdf.ln(5)
cur_ds=ds
id=m.group(2)
txt=m.group(3)
#print txt
align="L"
imagex=1
if id==part1:
pdf.set_text_color(244,92,66)
align="L"
imagex=1
if id==part2:
pdf.set_text_color(66,134,244)
#align="R"
#imagex=effective_page_width-40
align="L"
imagex=1
#print(id,align)
if "attached" in line:
if "jpg" in line:
#print(line)
m=re.search("(\S+.jpg)",line)
jpg=m.group(1)
img=zipchat.extract(jpg,"temp")
print("attaching ",img)
pdf.cell(h=5.0,align=align,w=0,txt=ts, border=0)
pdf.ln(5)
pdf.image(img,h=40,x=imagex)
pdf.ln(5)
os.remove(img)
else:
text=ts + ' ' + txt
#pdf.cell(h=5.0,align=align,w=0,txt=ts, border=0)
pdf.ln(5)
#pdf.multi_cell(w=effective_page_width,h=5,txt=txt, border=0,align=align)
pdf.multi_cell(w=effective_page_width,h=5,txt=ts + ":" + txt, border=0,align=align)
pdf.ln(5)
#pdf.cell(ln=n,h=5.0,align='L',w=0,txt=text, border=0)
#pdf.cell(ln=n,h=5.0,align='L',w=0,txt=line, border=0)
n+=1
print "printing pdf"
pdf.output('_chat.pdf','F')