forked from B16f00t/whapa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
whapa.py
2178 lines (1942 loc) · 128 KB
/
whapa.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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from colorama import init, Fore
from configparser import ConfigParser
import html
import distutils.dir_util
import argparse
import sqlite3
import time
import sys
import os
import shutil
import random
# Define global variable
arg_user = ""
arg_group = ""
message = ""
report_var = "None"
report_html = ""
report_group = ""
version = "1.55"
names_dict = {} # names wa.db
color = {} # participants color
current_color = "#5586e5" # default participant color
abs_path_file = os.path.abspath(__file__) # C:\Users\Desktop\whapa\libs\whapa.py
abs_path = os.path.split(abs_path_file)[0] # C:\Users\Desktop\whapa\libs\
split_path = abs_path.split(os.sep)[:-1] # ['C:', 'Users', 'Desktop', 'whapa']
whapa_path = os.path.sep.join(split_path) # C:\Users\Desktop\whapa
def banner():
""" Function Banner """
print(r"""
__ __.__ __________
/ \ / \ |__ _____ \______ \_____
\ \/\/ / | \\__ \ | ___/\__ \
\ /| Y \/ __ \| | / __ \_
\__/\ / |___| (____ /____| (____ /
\/ \/ \/ \/
------------- Whatsapp Parser -------------
""")
def help():
""" Function show help """
print(""" ** Author: Ivan Moreno a.k.a B16f00t
** Github: https://github.com/B16f00t
Usage: python3 whapa.py -h (for help)
""")
def db_connect(db):
""" Function connect to Database"""
if os.path.exists(db):
try:
with sqlite3.connect(db) as conn:
global cursor
cursor = conn.cursor()
cursor_rep = conn.cursor()
print("msgstore.db connected\n")
return cursor, cursor_rep
except Exception as e:
print("Error connecting to Database, ", e)
else:
print("msgstore.db doesn't exist")
exit()
def status(st):
""" Function message status"""
if st == 0 or st == 5: # 0 for me and 5 for target
return "Received", "✔✔"
elif st == 4:
return Fore.RED + "Waiting in server" + Fore.RESET, "✔"
elif st == 6:
return Fore.YELLOW + "System message" + Fore.RESET, "💻"
elif st == 8 or st == 10:
return Fore.BLUE + "Audio played" + Fore.RESET, "<font color=\"#0000ff \">✔✔</font>" # 10 for me and 8 for target
elif st == 13 or st == 12:
return Fore.BLUE + "Seen" + Fore.RESET, "<font color=\"#0000ff \">✔✔</font>"
else:
return str(st), ""
def size_file(obj):
""" Function objects size"""
if obj > 1048576:
obj = "(" + "{0:.2f}".format(obj / float(1048576)) + " MB)"
else:
obj = "(" + "{0:.2f}".format(obj / float(1024)) + " KB)"
return obj
def duration_file(obj):
""" Function duration tiMe"""
hour = (int(obj / 3600))
minu = int((obj - (hour * 3600)) / 60)
seco = obj - ((hour * 3600) + (minu * 60))
if obj >= 3600:
obj = (str(hour) + "h " + str(minu) + "m " + str(seco) + "s")
elif 60 < obj < 3600:
obj = (str(minu) + "m " + str(seco) + "s")
else:
obj = (str(seco) + "s")
return obj
def names(obj):
""" Function saves a name list if exits wa.db"""
# global names_dict
# names_dict = {} # jid : display_name
if os.path.exists(obj):
try:
with sqlite3.connect(obj) as conn:
cursor_name = conn.cursor()
sql_names = "SELECT jid, display_name FROM wa_contacts"
sql_names = cursor_name.execute(sql_names)
print("wa.db connected")
try:
for data in sql_names:
names_dict.update({data[0]: data[1]})
except Exception as e:
print("Error adding items in the dictionary:", e)
except Exception as e:
print("Error connecting to Database, ", e)
else:
print("wa database doesn't exist")
def gets_name(obj):
""" Function recover a name of the wa.db"""
if names_dict == {}: # No exists wa.db
return " "
else: # Exists Wa.db
if type(obj) is list: # It's a list
list_broadcast = []
for i in obj:
b = i + "@s.whatsapp.net"
if b in names_dict:
if names_dict[b] is not None:
list_broadcast.append(names_dict[b])
else:
list_broadcast.append(i)
else:
list_broadcast.append(i)
return " (" + ", ".join(list_broadcast) + ")"
else: # It's a string
if obj in names_dict:
if names_dict[obj] is not None:
return " (" + names_dict[obj] + ")"
else:
return ""
else:
return ""
def participants(obj):
""" Function saves all participant in an group or broadcast"""
sql_string_group = "SELECT jid, admin FROM group_participants WHERE gjid='" + str(obj) + "'"
sql_consult_group = cursor.execute(sql_string_group)
report_group = ""
for i in sql_consult_group:
if i[0]: # Others
hexcolor = ["#800000", "#00008B", "#006400", "#800080", "#8B4513", "#FF4500", "#2F4F4F", "#DC143C", "#696969", "#008B8B", "#D2691E", "#CD5C5C", "#4682B4"]
color[i[0].split("@")[0]] = random.choice(hexcolor)
global current_color
current_color = color.get(i[0].split("@")[0])
if i[1] and i[1] == 0: # User
if report_var == 'EN' or report_var == 'ES':
report_group += "<font color=\"{}\"> {} </font>, ".format(current_color, i[0].split("@")[0] + gets_name(i[0]))
else:
report_group += i[0].split("@")[0] + " " + Fore.YELLOW + gets_name(i[0]) + Fore.RESET + ", "
elif i[1] and i[1] > 0: # Admin
if report_var == 'EN' or report_var == 'ES':
report_group += "<font color=\"{}\"> {} </font> ***Admin***, ".format(current_color, i[0].split("@")[0] + gets_name(i[0]))
else:
report_group += i[0].split("@")[0] + Fore.YELLOW + gets_name(i[0]) + Fore.RESET + Fore.RED + "(Admin)" + Fore.RESET + ", "
else:
if report_var == 'EN' or report_var == 'ES':
report_group += "<font color=\"{}\"> {} </font>, ".format(current_color, i[0].split("@")[0] + gets_name(i[0]))
else:
report_group += i[0].split("@")[0] + " " + Fore.YELLOW + gets_name(i[0]) + Fore.RESET + ", "
else: # Me
current_color = "#000000"
if i[1] and i[1] == 0: # User
if report_var == 'EN':
report_group += "Phone user, "
elif report_var == 'ES':
report_group += "Usuario del teléfono, "
else:
report_group += "Me, "
elif i[1] and i[1] > 0: # Admin
if report_var == 'EN':
report_group += "<font color='{}'> Phone user </font> *** Admin ***, ".format(current_color)
elif report_var == 'ES':
report_group += "<font color='{}'> Usuario del teléfono </font> *** Admin ***, ".format(current_color)
else:
report_group += "Me" + Fore.RED + " (Admin)" + Fore.RESET + ", "
else: # Broadcast no user, no admin
if report_var == 'EN':
report_group += "<font color='{}'> Phone user </font>, ".format(current_color)
elif report_var == 'ES':
report_group += "<font color='{}'> Usuario del teléfono </font>, ".format(current_color)
else:
report_group += "Me, "
if (report_var == 'EN') or (report_var == 'ES'):
report_group = "<p style = 'border: 2px solid #CCCCCC; padding: 10px; background-color: #CCCCCC; color: black; font-family: arial,helvetica; font-size: 14px; font-weight: bold;'> " + report_group[:-2] + " </p>"
return report_group, color
def report(obj, html, local):
""" Function that makes the report """
# Copia los estilos
os.makedirs(local + "cfg", exist_ok=True)
if report_var == 'EN':
rep_ini = """<!DOCTYPE html>
<html lang='""" + report_var + """'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Report makes with Whatsapp Parser Tool">
<meta name="author" content="B16f00t">
<link rel="shortcut icon" href="./cfg/logo.png">
<title>Whatsapp Parser Tool v""" + version + """ Report</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="dist/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./cfg/chat.css" rel="stylesheet">
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #000000;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #cdcdcd;
}
#map {
height: 100px;
width: 100%;
}
</style>
<body background="./cfg/background.png">
<!-- Fixed navbar -->
<div class="container theme-showcase">
<div class="header">
<table style="width:100%">
<h1 align="left"><img src="./cfg/logo.png" height=128 width=128 align="center"> """ + company + """</h1>
<tr>
<th>Record</th>
<th>Unit / Company</th>
<th>Examiner</th>
<th>Date</th>
</tr>
<tr>
<td>""" + record + """</td>
<td>""" + unit + """</td>
<td>""" + examiner + """</td>
<td>""" + time.strftime('%d-%m-%Y', time.localtime()) + """</td>
</tr>
<tr>
<th colspan="4">Notes</th>
</tr>
<tr>
<td colspan="4">""" + notes + """</td>
</tr>
</table>
<h2 align=center> Chat </h2>
<h3 align=center> """ + arg_group + gets_name(arg_group) + arg_user + gets_name(arg_user + "@s.whatsapp.net") + """ </h3>
""" + report_group + """
</div>
<ul>"""
elif report_var == 'ES':
rep_ini = """<!DOCTYPE html>
<html lang='""" + report_var + """'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Informe creado por WhatsApp Parser Tool">
<meta name="author" content="B16f00t">
<link rel="shortcut icon" href="./cfg/logo.png">
<title>Whatsapp Parser Tool v""" + version + """ Report</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="dist/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./cfg/chat.css" rel="stylesheet">
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #000000;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #cdcdcd;
}
#map {
height: 100px;
width: 100%;
}
</style>
<body background="./cfg/background.png">
<!-- Fixed navbar -->
<div class="container theme-showcase">
<div class="header">
<table style="width:100%">
<h1 align="left"><img src="./cfg/logo.png" height=128 width=128 align="center"> """ + company + """</h1>
<tr>
<th>Registro</th>
<th>Unidad / Compañia</th>
<th>Examinador</th>
<th>Fecha</th>
</tr>
<tr>
<td>""" + record + """</td>
<td>""" + unit + """</td>
<td>""" + examiner + """</td>
<td>""" + time.strftime('%d-%m-%Y', time.localtime()) + """</td>
</tr>
<tr>
<th colspan="4">Observaciones</th>
</tr>
<tr>
<td colspan="4">""" + notes + """</td>
</tr>
</table>
<h2 align=center> Conversación </h2>
<h3 align=center> """ + arg_group + gets_name(arg_group) + arg_user + gets_name(arg_user + "@s.whatsapp.net") + """ </h3>
""" + report_group + """
</div>
<ul>"""
rep_end = """
<li>
<div class="bubble_empty">
</div>
</li>
</ul>
</div>
<!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<script src="docs-assets/js/holder.js"></script>
</body>
</html>
"""
os.makedirs(os.path.dirname(local), exist_ok=True)
with open(local + html, 'w', encoding="utf-8", errors="ignore") as f:
f.write(rep_ini + obj + rep_end)
def index_report(obj, html):
""" Function that makes the index report """
if report_var == "ES":
rep_ini = """<!DOCTYPE html>
<html lang='""" + report_var + """'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Informe realizado con Whatsapp Parser Tool">
<meta name="author" content="B16f00t">
<link rel="shortcut icon" href="./cfg/logo.png">
<title>Whatsapp Parser Tool v""" + version + """ Report Index</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="dist/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./cfg/chat.css" rel="stylesheet">
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
#map {
height: 100px;
width: 100%;
}
</style>
<body background="./cfg/background-index.png">
<!-- Fixed navbar -->
<div class="containerindex theme-showcase">
<h1 align="left"><img src="./cfg/logo.png" height=128 width=128 align="center"> """ + company + """</h1>
<h2 align=center> Listado de conversaciones </h2>
<div class="header">
<table style="width:100%">
""" + obj + """
</table>
</div>
</div>
<!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<script src="docs-assets/js/holder.js"></script>
</body>
</html>"""
elif report_var == "EN":
rep_ini = """<!DOCTYPE html>
<html lang='""" + report_var + """'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Report makes with Whatsapp Parser Tool">
<meta name="author" content="B16f00t">
<link rel="shortcut icon" href="./cfg/logo.png">
<title>Whatsapp Parser Tool v""" + version + """ Report Index</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="dist/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./cfg/chat.css" rel="stylesheet">
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
#map {
height: 100px;
width: 100%;
}
</style>
<body>
<body background="./cfg/background-index.png">
<!-- Fixed navbar -->
<div class="containerindex theme-showcase">
<h1 align="left"><img src="./cfg/logo.png" height=128 width=128 align="center"> """ + company + """</h1>
<h2 align=center> Chats list </h2>
<div class="header">
<table style="width:100%">
""" + obj + """
</table>
</div>
</div>
<!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<script src="docs-assets/js/holder.js"></script>
</body>
</html>"""
f = open(html, 'w', encoding="utf-8")
f.write(rep_ini)
f.close()
def reply(id, local):
""" Function look out answer messages """
sql_reply_str = "SELECT key_remote_jid, key_from_me, key_id, status, data, timestamp, media_url, media_mime_type, media_wa_type, media_size, media_name, media_caption, media_duration, latitude, longitude, " \
"remote_resource, edit_version, thumb_image, recipient_count, raw_data, starred, quoted_row_id, forwarded FROM messages_quotes WHERE _id = " + str(id)
sql_answer = cursor_rep.execute(sql_reply_str)
rep = sql_answer.fetchone()
ans = ""
reply_msj = ""
if rep is not None: # Message not deleted
if (str(rep[0]).split('@'))[1] == "g.us":
if int(rep[1]) == 1: # I post a message in a group
if report_var == 'EN':
reply_msj = "<font color=\"#FF0000\" > Me </font>"
elif report_var == 'ES':
reply_msj = "<font color=\"#FF0000\" > Yo </font>"
else:
ans = "Me"
elif int(rep[1]) == 0: # Somebody post a message in a group
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj = "<font color=\"#FF0000\" > " + (str(rep[15]).split('@'))[0] + gets_name(rep[15]) + " </font>"
else:
ans = (str(rep[15]).split('@'))[0] + gets_name(rep[15])
elif (str(rep[0]).split('@'))[1] == "s.whatsapp.net":
if int(rep[1]) == 1: # I send message to somebody
if report_var == 'EN':
reply_msj = "<font color=\"#FF0000\" > Me </font>"
elif report_var == 'ES':
reply_msj = "<font color=\"#FF0000\" > Yo </font>"
else:
ans = "Me"
elif int(rep[1]) == 0: # Someone sends me a message
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj = "<font color=\"#FF0000\" > " + (str(rep[0]).split('@'))[0] + gets_name(rep[0]) + " </font>"
else:
ans = (str(rep[0]).split('@'))[0] + gets_name(rep[0])
elif str(rep[0]) == "status@broadcast":
if os.path.isfile(local + "Media/.Statuses") is False:
distutils.dir_util.mkpath(local + "Media/.Statuses")
if int(rep[1]) == 1: # I post a Status
if report_var == 'EN':
reply_msj = "<font color=\"#FF0000\" > Me </font>"
elif report_var == 'ES':
reply_msj = "<font color=\"#FF0000\" > Yo </font>"
else:
ans = "Me"
elif int(rep[1]) == 0: # Somebody posts a Status
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj = "<font color=\"#FF0000\" > " + (str(rep[15]).split('@'))[0] + gets_name(rep[15]) + " </font>"
else:
ans = (str(rep[15]).split('@'))[0] + gets_name(rep[15])
if rep[22] and int(rep[22]) > 0: # Forwarded
if int(rep[22]) < 5:
if report_var == 'EN':
reply_msj += "<font color=\"#8b8878\" >➦ Forwarded</font><br>"
elif report_var == 'ES':
reply_msj += "<font color=\"#8b8878\" >➦ Reenviado</font><br>"
else:
ans += Fore.GREEN + "Forwarded" + Fore.RESET + "\n"
else:
if report_var == 'EN':
reply_msj += "<font color=\"#8b8878\" >➦➦ Forwarded many times</font><br>"
elif report_var == 'ES':
reply_msj += "<font color=\"#8b8878\" >➦➦ Reenviado muchas veces</font><br>"
else:
ans += Fore.RED + "Forwarded many times" + Fore.RESET + "\n"
if int(rep[8]) == 0: # media_wa_type 0, text message
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + html.escape(rep[4])
else:
ans += Fore.RED + " - Message: " + Fore.RESET + rep[4]
elif int(rep[8]) == 1: # media_wa_type 1, Image
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # Image doesn't exist
thumb = local + "Media/WhatsApp Images/IMG-" + str(rep[2]) + "-NotDownloaded.jpg"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if thumb != "Not downloaded":
thumb = local + thumb[2:]
if os.path.isfile(thumb) is False:
distutils.dir_util.mkpath(local + "Media/WhatsApp Images")
if rep[19]: # raw_data exists
with open(thumb, 'wb') as profile_file:
profile_file.write(rep[19])
if rep[11]: # media_caption
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb + " - " + html.escape(rep[11])
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + Fore.RED + " - Caption: " + Fore.RESET + rep[11] + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + "\n"
if (report_var == 'EN') or (report_var == 'ES'):
number = thumb.rfind("Media/WhatsApp Images/")
thumb = thumb[number - 1:].replace("\\", "/")
reply_msj += "<br> <a href=\"." + thumb + "\" target=\"_blank\"> <IMG SRC='." + thumb + "'width=\"100\" height=\"100\"/></a>"
elif int(rep[8]) == 2: # media_wa_type 2, Audio
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # Image doesn't exist
thumb = "Not downloaded"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb + " " + size_file(rep[9]) + " - " + duration_file(rep[12]) + "<br></br><audio controls> <source src=\"" + thumb + "\" type=\"" + rep[7] + "\"</audio>"
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + "\n"
ans += Fore.RED + "Type: " + Fore.RESET + rep[7] + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + Fore.RED + " - Duration: " + Fore.RESET + duration_file(rep[12]) + "\n"
elif int(rep[8]) == 3: # media_wa_type 3 Video
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # Video doesn't exist
thumb = local + "Media/WhatsApp Video/VID-" + str(rep[2]) + "-NotDownloaded.mp4"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if rep[19]: # raw_data exists
if thumb != "Not downloaded":
thumb = local + thumb[2:]
if os.path.isfile(thumb) is False:
distutils.dir_util.mkpath(local + "Media/WhatsApp Video")
with open(thumb, 'wb') as profile_file:
profile_file.write(rep[19])
if rep[11]: # media_caption
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb + " - " + html.escape(rep[11])
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + Fore.RED + " - Caption: " + Fore.RESET + rep[11] + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + "\n"
if (report_var == 'EN') or (report_var == 'ES'):
number = thumb.rfind("Media/WhatsApp Video/")
thumb = thumb[number - 1:].replace("\\", "/")
reply_msj += " " + size_file(rep[9]) + " - " + duration_file(rep[12])
reply_msj += "<br> <a href=\"." + thumb + "\" target=\"_blank\"> <IMG SRC='." + thumb + "'width=\"100\" height=\"100\"/></a>"
else:
ans += Fore.RED + "Type: " + Fore.RESET + rep[7] + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + Fore.RED + " - Duration: " + Fore.RESET + duration_file(rep[12]) + "\n"
elif int(rep[8]) == 4: # media_wa_type 4, Contact
if report_var == 'EN':
reply_msj += "<br>" + html.escape(rep[10]) + "<br>☎ Contact vCard"
if report_var == 'ES':
reply_msj += "<br>" + html.escape(rep[10]) + "<br>☎ Contacto vCard"
else:
ans += Fore.RED + " - Name: " + Fore.RESET + rep[10] + Fore.RED + " - Type:" + Fore.RESET + " Contact vCard\n"
elif int(rep[8]) == 5: # media_wa_type 5, Location
if rep[6]: # media_url exists
if rep[10]: # media_name exists
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + html.escape(rep[6]) + " - " + html.escape(rep[10]) + "<br>"
else:
ans += Fore.RED + " - Url: " + Fore.RESET + rep[6] + Fore.RED + " - Name: " + Fore.RESET + rep[10] + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + html.escape(rep[6]) + "<br>"
else:
ans += Fore.RED + " - Url: " + Fore.RESET + rep[6] + "\n"
else:
if rep[10]:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + html.escape(rep[10]) + "<br>"
else:
ans += Fore.RED + " - Name: " + Fore.RESET + rep[10] + "\n"
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + "<iframe width='300' height='150' id='gmap_canvas' src='https://maps.google.com/maps?q={}%2C{}&t=&z=15&ie=UTF8&iwloc=&output=embed' frameborder='0' scrolling='no' marginheight='0' marginwidth='0'></iframe>".format(str(rep[13]), str(rep[14]))
else:
ans += Fore.RED + "Type: " + Fore.RESET + "Location" + Fore.RED + " - Lat: " + Fore.RESET + str(rep[13]) + Fore.RED + " - Long: " + Fore.RESET + str(rep[14]) + "\n"
elif int(rep[8]) == 8: # media_wa_type 8, Audio / Video Call
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + "📞 " + str(rep[11]).capitalize() + " " + duration_file(rep[12])
else:
ans += Fore.RED + " - Call :" + Fore.RESET + str(rep[11]).capitalize() + Fore.RED + " - Duration: " + Fore.RESET + duration_file(rep[12]) + "\n"
elif int(rep[8]) == 9: # media_wa_type 9, Application
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # App doesn't exist
thumb = local + "Media/WhatsApp Documents/DOC-" + str(rep[2]) + "-NotDownloaded"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if thumb != "Not downloaded":
thumb = local + thumb[2:]
if os.path.isfile(thumb) is False:
distutils.dir_util.mkpath(local + "Media/WhatsApp Documents")
if rep[19]: # raw_data exists
with open(thumb +"jpg", 'wb') as profile_file:
profile_file.write(rep[19])
if rep[11]: # media_caption
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb + " - " + html.escape(rep[11])
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + Fore.RED + " - Caption: " + Fore.RESET + rep[11] + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + "\n"
if rep[12] >= 0:
if report_var == 'EN':
reply_msj += " " + size_file(rep[9]) + " - " + str(rep[12]) + " Pages"
elif report_var == 'ES':
reply_msj += " " + size_file(rep[9]) + " - " + str(rep[12]) + " Páginas"
else:
ans += Fore.RED + "Type: " + Fore.RESET + rep[7] + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + Fore.RED + " - Pages: " + Fore.RESET + str(rep[12]) + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += " " + size_file(rep[9])
else:
ans += Fore.RED + "Type: " + Fore.RESET + rep[7] + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + "\n"
if (report_var == 'EN') or (report_var == 'ES'):
number = thumb.rfind("Media/WhatsApp Documents/")
thumb = thumb[number - 1:].replace("\\", "/")
reply_msj += "<br> <a href=\"." + thumb + "\" target=\"_blank\"> <IMG SRC='." + thumb + ".jpg' width=\"100\" height=\"100\"/></a>"
elif int(rep[8]) == 10: # media_wa_type 10, Video/Audio call lost
if report_var == 'EN':
reply_msj += "<br>" + "📞 Missed" + str(rep[11]).capitalize() + " call"
elif report_var == 'ES':
reply_msj += "<br>" + "📞 " + str(rep[11]).capitalize() + " llamada perdida"
else:
ans += Fore.RED + " - Message: " + Fore.RESET + "Missed " + str(rep[11]).capitalize() + " call\n"
elif int(rep[8]) == 13: # media_wa_type 13 Gif
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # GIF doesn't exist
thumb = local + "Media/WhatsApp Animated Gifs/VID-" + str(rep[2]) + "-NotDownloaded.mp4"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if thumb != "Not downloaded":
thumb = local + thumb[2:]
if os.path.isfile(thumb) is False:
distutils.dir_util.mkpath(local + "Media/WhatsApp Animated Gifs")
if rep[19]: # raw_data exists
with open(thumb, 'wb') as profile_file:
profile_file.write(rep[19])
if rep[11]: # media_caption
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb + " - " + html.escape(rep[11])
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + Fore.RED + " - Caption: " + Fore.RESET + rep[11] + "\n"
else:
if (report_var == 'EN') or (report_var == 'ES'):
reply_msj += "<br>" + thumb
else:
ans += Fore.RED + " - Name: " + Fore.RESET + thumb + "\n"
if (report_var == 'EN') or (report_var == 'ES'):
number = thumb.rfind("Media/WhatsApp Animated Gifs/")
thumb = thumb[number - 1:].replace("\\", "/")
reply_msj += " - Gif - " + size_file(rep[9]) + " " + duration_file(rep[12]) + "<br> <a href=\"." + thumb + "\" target=\"_blank\"> <IMG SRC='." + thumb + "'width=\"100\" height=\"100\"/></a>"
else:
ans += Fore.RED + "Type: " + Fore.RESET + "Gif" + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + Fore.RED + " - Duration: " + Fore.RESET + duration_file(rep[12]) + "\n"
elif int(rep[8]) == 14: # Vcard Multiple
concat = ""
chain = str(rep[19]).split('BEGIN:VCARD')
for i in chain[1:]:
concat += "BEGIN:VCARD"
concat += i.split('END:VCARD')[0] + "END:VCARD"
if report_var == 'EN':
reply_msj += "<br>" + html.escape(rep[10]) + "<br>☎ Contact vCard</br>" + html.escape(concat)
elif report_var == 'ES':
reply_msj += "<br>" + html.escape(rep[10]) + "<br>☎ Contacto vCard</br>" + html.escape(concat)
else:
ans += Fore.RED + " - Name: " + Fore.RESET + rep[10] + Fore.RED + " - Type:" + Fore.RESET + " Contact vCard" + concat + "\n"
elif int(rep[8]) == 15: # media_wa_type 15, Deleted Object
if int(rep[16]) == 5: # edit_version 5, deleted for me
if report_var == 'EN':
reply_msj += "<br>" + "Message deleted for Me"
elif report_var == 'ES':
reply_msj += "<br>" + "Mensaje eliminado para mí"
else:
ans += Fore.RED + " - Message: " + Fore.RESET + "Message deleted for Me\n"
elif int(rep[16]) == 7: # edit_version 7, deleted for all
if report_var == 'EN':
reply_msj += "<br>" + "Message deleted for all participants"
elif report_var == 'ES':
reply_msj += "<br>" + "Mensaje eliminado para todos los destinatarios"
else:
ans += Fore.RED + " - Message: " + Fore.RESET + "Message deleted for all participants\n"
elif int(rep[8]) == 16: # media_wa_type 16, Share location
caption = ""
if rep[11]:
caption = rep[11]
if report_var == 'EN':
reply_msj += "<br>" + "Real time location (" + str(rep[13]) + "," + str(rep[14]) + ") - " + html.escape(caption) + "\n"
reply_msj += " <br><a href=\"https://www.google.es/maps/search/(" + str(rep[13]) + "," + str(rep[14]) + ")\" target=\"_blank\"> <img src=\"http://maps.google.com/maps/api/staticmap?center=" + str(rep[13]) + "," + str(rep[14]) + "&zoom=16&size=300x150&markers=size:mid|color:red|label:A|" + str(rep[13]) + "," + str(rep[14]) + "&sensor=false\"/></a>"
elif report_var == 'ES':
reply_msj += "<br>" + "Ubicación en tiempo real (" + str(rep[13]) + "," + str(rep[14]) + ") - " + html.escape(caption) + "\n"
reply_msj += "<br><iframe width='300' height='150' id='gmap_canvas' src='https://maps.google.com/maps?q={}%2C{}&t=&z=15&ie=UTF8&iwloc=&output=embed' frameborder='0' scrolling='no' marginheight='0' marginwidth='0'></iframe>".format(str(rep[13]), str(rep[14]))
else:
ans += Fore.RED + " - Type: " + Fore.RESET + "Real time location " + Fore.RED + "- Caption: " + Fore.RESET + caption + Fore.RED + " - Lat: " + Fore.RESET + str(rep[13]) + Fore.RED + " - Long: " + Fore.RESET + str(rep[14]) + Fore.RED + " - Duration: " + Fore.RESET + duration_file(rep[12]) + "\n"
elif int(rep[8]) == 20: # media_wa_type 20 Sticker
chain = rep[17].split(b'\x77\x02')[0]
i = chain.rfind(b"Media/")
b = len(chain)
if i == -1: # Sticker doesn't exist
thumb = "Not downloaded"
else:
thumb = (b"./" + chain[i:b]).decode('UTF-8', 'ignore')
if (report_var == 'EN') or (report_var == 'ES'):
number = thumb.rfind("Media/WhatsApp Stickers/")
thumb = thumb[number - 1:].replace("\\", "/")
reply_msj += "<br>" + "Sticker - " + size_file(rep[9]) + "<br> <a href=\"." + thumb + "\" target=\"_blank\"> <IMG SRC='." + thumb + "'width=\"100\" height=\"100\"/></a>"
else:
ans += Fore.RED + " - Type: " + Fore.RESET + "Sticker" + Fore.RED + " - Size: " + Fore.RESET + str(rep[9]) + " bytes " + size_file(rep[9]) + Fore.RED + "\n"
else: # Deleted Message
if report_var == 'EN':
reply_msj = "<br>" + "Deleted message"
elif report_var == 'ES':
reply_msj = "<br>" + "Mensaje eliminado"
else:
ans += " - Deleted message"
return ans, reply_msj
def messages(consult, rows, report_html, local):
""" Function that show database messages """
try:
n_mes = 0
rep_med = "" # Saves the complete chat
if arg_group and report_var == "None":
print(Fore.RED + "Participants" + Fore.RESET)
print(report_group)
for data in consult:
try:
report_msj = "" # Saves each message
report_name = "" # Saves the chat sender
message = "" # Saves each msg
sys.stdout.write("\rMessage {}/{} - ID {}".format(str(n_mes+1), str(rows), str(data[23])))
sys.stdout.flush()
if int(data[8]) != -1: # media_wa_type -1 "Start DB"
# Groups
if (str(data[0]).split('@'))[1] == "g.us":
if int(data[1]) == 1:
if int(data[3]) == 6: # Group System Message
if report_var == 'EN':
report_name = "System Message"
elif report_var == 'ES':
report_name = "Mensaje de Sistema"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + data[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + "\n"
else: # I send message to a group
if report_var == 'EN':
report_name = "Me"
elif report_var == 'ES':
report_name = "Yo"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + "Me" + Fore.GREEN + " to " + Fore.RESET + data[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + "\n"
elif int(data[1]) == 0: # Somebody post a message in a group
if (report_var == 'EN') or (report_var == 'ES'):
current_color = color.get((str(data[15]).split('@'))[0])
if not current_color:
current_color = "#5586e5"
report_name = "<font color='{}'> {} </font>".format(current_color, (str(data[15]).split('@'))[0] + gets_name(data[15]))
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + data[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + Fore.GREEN + ", participant " + Fore.RESET + (str(data[15]).split('@'))[0] + " " + Fore.YELLOW + gets_name(data[15]) + Fore.RESET + "\n"
# Users
elif (str(data[0]).split('@'))[1] == "s.whatsapp.net":
if data[15] and (str(data[15]).split('@'))[1] == "broadcast":
if int(data[1]) == 1: # I send to somebody message by broadcast
if report_var == 'EN':
report_name = "📣 Me"
elif report_var == 'ES':
report_name = "📣 Yo"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From" + Fore.RESET + " Me" + Fore.GREEN + " to " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + Fore.GREEN + " by broadcast" + Fore.RESET + "\n"
elif int(data[1]) == 0: # Someone sends me a message by broadcast
if (report_var == 'EN') or (report_var == 'ES'):
report_name = "📣" + (str(data[0]).split('@'))[0] + gets_name(data[0])
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + Fore.GREEN + " to" + Fore.RESET + " Me" + Fore.GREEN + " by broadcast" + Fore.RESET + "\n"
else:
if int(data[1]) == 1:
if int(data[3]) == 6: # User system message
if report_var == 'EN':
report_name = "System Message"
elif report_var == 'ES':
report_name = "Mensaje de Sistema"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + "\n"
else: # I send message to someone
if report_var == 'EN':
report_name = "Me"
elif report_var == 'ES':
report_name = "Yo"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From" + Fore.RESET + " Me" + Fore.GREEN + " to " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + "\n"
elif int(data[1]) == 0: # Someone sends me a message
if (report_var == 'EN') or (report_var == 'ES'):
report_name = (str(data[0]).split('@'))[0] + gets_name(data[0])
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + Fore.GREEN + " to" + Fore.RESET + " Me\n"
# Broadcast and Status
elif (str(data[0]).split('@'))[1] == "broadcast":
# Status
if str(data[0]) == "status@broadcast":
if os.path.isfile(local + "Media/.Statuses") is False:
distutils.dir_util.mkpath(local + "Media/.Statuses")
if int(data[1]) == 1: # I post a Status
if report_var == 'EN':
report_name = "Me"
elif report_var == 'ES':
report_name = "Yo"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + "Me - Post status" + "\n"
elif int(data[1]) == 0: # Somebody posts a Status
if report_var == 'EN':
report_name = "Posts Status - " + (str(data[15]).split('@'))[0] + gets_name(data[15])
elif report_var == 'ES':
report_name = "Publica Estado - " + (str(data[15]).split('@'))[0] + gets_name(data[15])
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + (str(data[15]).split('@'))[0] + Fore.YELLOW + gets_name(data[15]) + Fore.RESET + Fore.GREEN + " posts status" + Fore.RESET + "\n"
# Broadcast
else:
if int(data[3]) == 6: # Broadcast system message
if report_var == 'EN':
report_name = "System Message"
elif report_var == 'ES':
report_name = "Mensaje de Sistema"
else:
message = Fore.RED + "\n--------------------------------------------------------------------------------" + Fore.RESET + "\n"
message += Fore.GREEN + "From " + Fore.RESET + (str(data[0]).split('@'))[0] + Fore.YELLOW + gets_name(data[0]) + Fore.RESET + "\n"
else: # I send a message to a broadcast list
list_broadcast = (str(data[15])).replace(',', '').split('@s.whatsapp.net')
list_copy = []
for i in list_broadcast:
list_copy.append(i + " " + Fore.YELLOW + gets_name(i + "@s.whatsapp.net") + Fore.RESET)
list_copy.pop()
list_copy = ", ".join(list_copy)
if report_var == 'EN':