| skipped 16 lines |
17 | 17 | | import getpass |
18 | 18 | | import click |
19 | 19 | | import re |
20 | | - | import textwrap |
21 | 20 | | import time |
22 | | - | import pprint |
| 21 | + | |
23 | 22 | | |
24 | 23 | | from telepathy.utils import ( |
25 | 24 | | print_banner, |
| skipped 2 lines |
28 | 27 | | process_message, |
29 | 28 | | process_description, |
30 | 29 | | parse_tg_date, |
31 | | - | parse_html_page |
| 30 | + | parse_html_page, |
| 31 | + | print_shell, |
| 32 | + | createPlaceholdeCls |
32 | 33 | | ) |
33 | 34 | | import telepathy.const as const |
34 | 35 | | |
| skipped 13 lines |
48 | 49 | | from telethon import TelegramClient, functions, types, utils |
49 | 50 | | from telethon.utils import get_display_name, get_message_id |
50 | 51 | | from alive_progress import alive_bar |
51 | | - | from bs4 import BeautifulSoup |
52 | | - | |
53 | 52 | | |
54 | 53 | | @click.command() |
55 | 54 | | @click.option( |
| skipped 152 lines |
208 | 207 | | exports = [] |
209 | 208 | | |
210 | 209 | | print("Exporting...") |
211 | | - | |
212 | 210 | | # progress bar |
213 | | - | |
214 | 211 | | for Dialog in await client.get_dialogs(): |
215 | 212 | | try: |
216 | 213 | | if Dialog.entity.username: |
| skipped 7 lines |
224 | 221 | | _desc = process_description( |
225 | 222 | | group_description, user_language |
226 | 223 | | ) |
227 | | - | |
228 | | - | original_language = _desc[ |
229 | | - | "original_language" |
230 | | - | ] |
231 | 224 | | translated_description = _desc["translated_text"] |
232 | 225 | | |
233 | 226 | | if Dialog.entity.broadcast is True: |
| skipped 65 lines |
299 | 292 | | |
300 | 293 | | except AttributeError: |
301 | 294 | | pass |
302 | | - | |
303 | 295 | | else: |
304 | | - | |
305 | 296 | | for t in target: |
306 | 297 | | target_clean = t |
307 | 298 | | alphanumeric = "" |
308 | | - | |
309 | 299 | | |
310 | 300 | | for character in target_clean: |
311 | 301 | | if character.isalnum(): |
| skipped 117 lines |
429 | 419 | | ] |
430 | 420 | | |
431 | 421 | | translated_description = _desc["translated_text"] |
432 | | - | |
433 | | - | preferredWidth = 70 |
434 | | - | descript = Fore.GREEN + "Description: " + Style.RESET_ALL |
435 | | - | prefix = descript |
436 | | - | wrapper_d = textwrap.TextWrapper( |
437 | | - | initial_indent=prefix, |
438 | | - | width=preferredWidth, |
439 | | - | subsequent_indent=" ", |
440 | | - | ) |
441 | | - | |
442 | | - | trans_descript = Fore.GREEN + "Translated: " + Style.RESET_ALL |
443 | | - | prefix = trans_descript |
444 | | - | wrapper_td = textwrap.TextWrapper( |
445 | | - | initial_indent=prefix, |
446 | | - | width=preferredWidth, |
447 | | - | subsequent_indent=" ", |
448 | | - | ) |
449 | | - | |
450 | 422 | | group_description = ('"' + group_description + '"') |
451 | 423 | | |
452 | 424 | | if entity.broadcast is True: |
| skipped 17 lines |
470 | 442 | | else: |
471 | 443 | | group_status = "None" |
472 | 444 | | |
473 | | - | restrict = Fore.GREEN + "Restrictions:" + Style.RESET_ALL |
474 | | - | prefix = restrict + " " |
475 | | - | preferredWidth = 70 |
476 | | - | wrapper_r = textwrap.TextWrapper( |
477 | | - | initial_indent=prefix, |
478 | | - | width=preferredWidth, |
479 | | - | subsequent_indent=" ", |
480 | | - | ) |
481 | | - | |
| 445 | + | found_participants = 0 |
| 446 | + | found_percentage = 0 |
482 | 447 | | if chat_type != "Channel": |
483 | 448 | | members = [] |
484 | | - | all_participants = [] |
485 | 449 | | all_participants = await client.get_participants(t, limit=5000) |
486 | | - | |
487 | 450 | | members_df = None |
488 | 451 | | for user in all_participants: |
489 | 452 | | members_df = pd.DataFrame( |
| skipped 39 lines |
529 | 492 | | else: |
530 | 493 | | pass |
531 | 494 | | |
532 | | - | color_print_green(" ⬠Chat details", "") |
533 | | - | color_print_green(" â Title: ", str(entity.title)) |
534 | | - | color_print_green(" â ", wrapper_d.fill(group_description)) |
535 | | - | if translated_description != group_description: |
536 | | - | color_print_green(" â ", wrapper_td.fill(translated_description)) |
537 | | - | color_print_green( |
538 | | - | " â Total participants: ", str(total_participants) |
539 | | - | ) |
540 | | - | |
| 495 | + | setattr(entity, "group_description", group_description) |
| 496 | + | setattr(entity, "group_status", group_status) |
| 497 | + | setattr(entity, "group_username", group_username) |
| 498 | + | setattr(entity, "first_post", first_post) |
| 499 | + | setattr(entity, "group_url", group_url) |
| 500 | + | setattr(entity, "chat_type", chat_type) |
| 501 | + | setattr(entity, "translated_description", translated_description) |
| 502 | + | setattr(entity, "total_participants", total_participants) |
541 | 503 | | if chat_type != "Channel": |
542 | | - | color_print_green( |
543 | | - | " â Participants found: ", |
544 | | - | str(found_participants) |
545 | | - | + " (" |
546 | | - | + str(format(found_percentage, ".2f")) |
547 | | - | + "%)", |
548 | | - | ) |
| 504 | + | setattr(entity, "found_participants", found_participants) |
| 505 | + | setattr(entity, "found_percentage", found_percentage) |
| 506 | + | setattr(entity, "memberlist_filename", memberlist_filename) |
549 | 507 | | else: |
550 | | - | found_participants = "N/A" |
551 | | - | |
552 | | - | color_print_green(" â Username: ", str(group_username)) |
553 | | - | color_print_green(" â URL: ", str(group_url)) |
554 | | - | color_print_green(" â Chat type: ", str(chat_type)) |
555 | | - | color_print_green(" â Chat id: ", str(entity.id)) |
556 | | - | color_print_green(" â Access hash: ", str(entity.access_hash)) |
557 | | - | |
| 508 | + | setattr(entity, "found_participants", found_participants) |
| 509 | + | print_flag = "group_recap" |
558 | 510 | | if chat_type == "Channel": |
559 | | - | scam_status = str(entity.scam) |
560 | | - | color_print_green(" â Scam: ", str(scam_status)) |
561 | | - | else: |
562 | | - | scam_status = "N/A" |
| 511 | + | print_flag = "channel_recap" |
563 | 512 | | |
564 | | - | color_print_green(" â First post date: ", str(first_post)) |
565 | | - | |
566 | | - | if chat_type != "Channel": |
567 | | - | color_print_green( |
568 | | - | " â Memberlist saved to: ", memberlist_filename |
569 | | - | ) |
570 | | - | |
571 | | - | color_print_green( |
572 | | - | " â ", wrapper_r.fill(group_status) |
573 | | - | ) |
574 | | - | #print("\n") |
| 513 | + | print_shell(print_flag, entity) |
575 | 514 | | |
576 | 515 | | log.append( |
577 | 516 | | [ |
| skipped 8 lines |
586 | 525 | | chat_type, |
587 | 526 | | entity.id, |
588 | 527 | | entity.access_hash, |
589 | | - | scam_status, |
| 528 | + | str(entity.scam), |
590 | 529 | | date, |
591 | 530 | | mtime, |
592 | 531 | | group_status, |
| skipped 146 lines |
739 | 678 | | df01 = value_count.rename_axis("unique_values").reset_index( |
740 | 679 | | name="counts" |
741 | 680 | | ) |
742 | | - | |
743 | | - | top_forward_one = df01.iloc[0]["unique_values"] |
744 | | - | top_value_one = df01.iloc[0]["counts"] |
745 | | - | top_forward_two = df01.iloc[1]["unique_values"] |
746 | | - | top_value_two = df01.iloc[1]["counts"] |
747 | | - | top_forward_three = df01.iloc[2]["unique_values"] |
748 | | - | top_value_three = df01.iloc[2]["counts"] |
749 | | - | top_forward_four = df01.iloc[3]["unique_values"] |
750 | | - | top_value_four = df01.iloc[3]["counts"] |
751 | | - | top_forward_five = df01.iloc[4]["unique_values"] |
752 | | - | top_value_five = df01.iloc[4]["counts"] |
753 | | - | |
754 | | - | forward_one = ( |
755 | | - | str(top_forward_one) |
| 681 | + | report_forward = createPlaceholdeCls() |
| 682 | + | report_forward.forward_one = ( |
| 683 | + | str(df01.iloc[0]["unique_values"]) |
756 | 684 | | + ", " |
757 | | - | + str(top_value_one) |
| 685 | + | + str(df01.iloc[0]["counts"]) |
758 | 686 | | + " forwarded messages" |
759 | 687 | | ) |
760 | | - | forward_two = ( |
761 | | - | str(top_forward_two) |
762 | | - | + ", " |
763 | | - | + str(top_value_two) |
764 | | - | + " forwarded messages" |
| 688 | + | report_forward.forward_two = ( |
| 689 | + | str(df01.iloc[1]["unique_values"]) |
| 690 | + | + ", " |
| 691 | + | + str(df01.iloc[1]["counts"]) |
| 692 | + | + " forwarded messages" |
765 | 693 | | ) |
766 | | - | forward_three = ( |
767 | | - | str(top_forward_three) |
768 | | - | + ", " |
769 | | - | + str(top_value_three) |
770 | | - | + " forwarded messages" |
| 694 | + | report_forward.forward_three = ( |
| 695 | + | str(df01.iloc[2]["unique_values"]) |
| 696 | + | + ", " |
| 697 | + | + str(df01.iloc[2]["counts"]) |
| 698 | + | + " forwarded messages" |
771 | 699 | | ) |
772 | | - | forward_four = ( |
773 | | - | str(top_forward_four) |
774 | | - | + ", " |
775 | | - | + str(top_value_four) |
776 | | - | + " forwarded messages" |
| 700 | + | report_forward.forward_four = ( |
| 701 | + | str(df01.iloc[3]["unique_values"]) |
| 702 | + | + ", " |
| 703 | + | + str(df01.iloc[3]["counts"]) |
| 704 | + | + " forwarded messages" |
777 | 705 | | ) |
778 | | - | forward_five = ( |
779 | | - | str(top_forward_five) |
780 | | - | + ", " |
781 | | - | + str(top_value_five) |
782 | | - | + " forwarded messages" |
| 706 | + | report_forward.forward_five = ( |
| 707 | + | str(df01.iloc[4]["unique_values"]) |
| 708 | + | + ", " |
| 709 | + | + str(df01.iloc[4]["counts"]) |
| 710 | + | + " forwarded messages" |
783 | 711 | | ) |
784 | | - | |
785 | 712 | | df02 = forwards_df.Source.unique() |
786 | | - | unique_forwards = len(df02) |
787 | | - | |
788 | | - | #print("\n") |
789 | | - | color_print_green(" [+] Forward scrape complete", "") |
790 | | - | color_print_green(" ⬠Statistics", "") |
791 | | - | color_print_green( |
792 | | - | " â Forwarded messages found: ", str(forward_count) |
793 | | - | ) |
794 | | - | color_print_green( |
795 | | - | " â Forwards from active public chats: ", |
796 | | - | str(forwards_found), |
797 | | - | ) |
798 | | - | color_print_green( |
799 | | - | " â Unique forward sources: ", str(unique_forwards) |
800 | | - | ) |
801 | | - | color_print_green( |
802 | | - | " â Top forward source 1: ", str(forward_one) |
803 | | - | ) |
804 | | - | color_print_green( |
805 | | - | " â Top forward source 2: ", str(forward_two) |
806 | | - | ) |
807 | | - | color_print_green( |
808 | | - | " â Top forward source 3: ", str(forward_three) |
809 | | - | ) |
810 | | - | color_print_green( |
811 | | - | " â Top forward source 4: ", str(forward_four) |
812 | | - | ) |
813 | | - | color_print_green( |
814 | | - | " â Top forward source 5: ", str(forward_five) |
815 | | - | ) |
816 | | - | color_print_green(" â Edgelist saved to: ", edgelist_file) |
817 | | - | #print("\n") |
| 713 | + | report_forward.unique_forwards = len(df02) |
| 714 | + | report_forward.edgelist_file = edgelist_file |
| 715 | + | print_shell("forwarder_stat",report_forward) |
818 | 716 | | |
819 | 717 | | else: |
820 | 718 | | print( |
| skipped 8 lines |
829 | 727 | | if comp_check is True: |
830 | 728 | | |
831 | 729 | | messages = client.iter_messages(t) |
832 | | - | |
833 | 730 | | message_list = [] |
834 | 731 | | forwards_list = [] |
835 | | - | |
836 | 732 | | user_reaction_list = [] |
837 | | - | |
838 | 733 | | replies_list = [] |
839 | 734 | | user_replier_list = [] |
840 | | - | |
841 | 735 | | timecount = [] |
842 | | - | |
843 | 736 | | forward_count = 0 |
844 | 737 | | private_count = 0 |
845 | 738 | | |
| skipped 104 lines |
950 | 843 | | "Message ID", |
951 | 844 | | "Reply ID", |
952 | 845 | | "Display_name", |
953 | | - | "ID", |
| 846 | + | "User ID", |
954 | 847 | | "Message_text", |
955 | 848 | | "Original_language", |
956 | 849 | | "Translated_text", |
| skipped 103 lines |
1060 | 953 | | else: |
1061 | 954 | | has_media = 'FALSE' |
1062 | 955 | | |
1063 | | - | post_url = "https://t.me/s/" + t + "/" + message.id |
| 956 | + | post_url = "https://t.me/s/" + t + "/" + str(message.id) |
1064 | 957 | | |
1065 | 958 | | message_list.append( |
1066 | 959 | | [ |
| skipped 191 lines |
1258 | 1151 | | pass |
1259 | 1152 | | |
1260 | 1153 | | messages_found = int(c_archive.To.count()) - 1 |
1261 | | - | message_frequency_count = {} |
1262 | | - | message_text = {} |
1263 | | - | word_count = {} |
1264 | | - | most_used_words = {} |
1265 | | - | most_used_words_filtered = {} |
1266 | | - | # message stats, top words |
| 1154 | + | report_obj = createPlaceholdeCls() |
| 1155 | + | report_obj.messages_found = messages_found |
| 1156 | + | report_obj.file_archive = file_archive |
1267 | 1157 | | |
1268 | | - | if chat_type != "Channel": |
1269 | | - | pcount = c_archive.Display_name.count() |
| 1158 | + | if chat_type == "Channel": |
| 1159 | + | print_shell("channel_stat", report_obj) |
| 1160 | + | else: |
1270 | 1161 | | pvalue_count = c_archive["Display_name"].value_counts() |
1271 | 1162 | | df03 = pvalue_count.rename_axis( |
1272 | 1163 | | "unique_values" |
1273 | 1164 | | ).reset_index(name="counts") |
1274 | 1165 | | |
1275 | | - | top_poster_one = str(df03.iloc[0]["unique_values"]) |
1276 | | - | top_pvalue_one = df03.iloc[0]["counts"] |
1277 | | - | top_poster_two = str(df03.iloc[1]["unique_values"]) |
1278 | | - | top_pvalue_two = df03.iloc[1]["counts"] |
1279 | | - | top_poster_three = str(df03.iloc[2]["unique_values"]) |
1280 | | - | top_pvalue_three = df03.iloc[2]["counts"] |
1281 | | - | top_poster_four = str(df03.iloc[3]["unique_values"]) |
1282 | | - | top_pvalue_four = df03.iloc[3]["counts"] |
1283 | | - | top_poster_five = str(df03.iloc[4]["unique_values"]) |
1284 | | - | top_pvalue_five = df03.iloc[4]["counts"] |
| 1166 | + | ''' |
| 1167 | + | message_frequency_count = {} |
| 1168 | + | message_text = {} |
| 1169 | + | word_count = {} |
| 1170 | + | most_used_words = {} |
| 1171 | + | most_used_words_filtered = {} |
| 1172 | + | ''' |
| 1173 | + | #message stats, top words |
1285 | 1174 | | |
1286 | | - | poster_one = ( |
1287 | | - | str(top_poster_one) |
| 1175 | + | report_obj.poster_one = ( |
| 1176 | + | str(df03.iloc[0]["unique_values"]) |
1288 | 1177 | | + ", " |
1289 | | - | + str(top_pvalue_one) |
| 1178 | + | + str(df03.iloc[0]["counts"]) |
1290 | 1179 | | + " messages" |
1291 | 1180 | | ) |
1292 | | - | poster_two = ( |
1293 | | - | str(top_poster_two) |
| 1181 | + | |
| 1182 | + | report_obj.poster_two = ( |
| 1183 | + | str(df03.iloc[1]["unique_values"]) |
1294 | 1184 | | + ", " |
1295 | | - | + str(top_pvalue_two) |
| 1185 | + | + str(df03.iloc[2]["counts"]) |
1296 | 1186 | | + " messages" |
1297 | 1187 | | ) |
1298 | | - | poster_three = ( |
1299 | | - | str(top_poster_three) |
| 1188 | + | |
| 1189 | + | report_obj.poster_three = ( |
| 1190 | + | str(df03.iloc[2]["unique_values"]) |
1300 | 1191 | | + ", " |
1301 | | - | + str(top_pvalue_three) |
| 1192 | + | + str(df03.iloc[2]["counts"]) |
1302 | 1193 | | + " messages" |
1303 | 1194 | | ) |
1304 | | - | poster_four = ( |
1305 | | - | str(top_poster_four) |
| 1195 | + | |
| 1196 | + | report_obj.poster_four = ( |
| 1197 | + | str(df03.iloc[3]["unique_values"]) |
1306 | 1198 | | + ", " |
1307 | | - | + str(top_pvalue_four) |
| 1199 | + | + df03.iloc[3]["counts"] |
1308 | 1200 | | + " messages" |
1309 | 1201 | | ) |
1310 | | - | poster_five = ( |
1311 | | - | str(top_poster_five) |
| 1202 | + | |
| 1203 | + | report_obj.poster_five = ( |
| 1204 | + | str(df03.iloc[4]["unique_values"]) |
1312 | 1205 | | + ", " |
1313 | | - | + str(top_pvalue_five) |
| 1206 | + | + str(df03.iloc[4]["counts"]) |
1314 | 1207 | | + " messages" |
1315 | 1208 | | ) |
1316 | 1209 | | |
1317 | 1210 | | df04 = c_archive.Display_name.unique() |
1318 | | - | plength = len(df03) |
1319 | 1211 | | unique_active = len(df04) |
| 1212 | + | report_obj.unique_active = unique_active |
| 1213 | + | print_shell("group_stat", report_obj) |
1320 | 1214 | | |
1321 | | - | elif reply_analysis is True: |
| 1215 | + | if reply_analysis is True: |
| 1216 | + | |
1322 | 1217 | | if len(replies_list) > 0: |
1323 | | - | replier_count = c_repliers["User id"].count() |
1324 | | - | replier_value_count = c_repliers["User id"].value_counts() |
| 1218 | + | replier_value_count = c_repliers["User ID"].value_counts() |
1325 | 1219 | | replier_df = replier_value_count.rename_axis( |
1326 | 1220 | | "unique_values" |
1327 | 1221 | | ).reset_index(name="counts") |
1328 | 1222 | | |
1329 | | - | top_replier_one = str(replier_df.iloc[0]["unique_values"]) |
1330 | | - | top_replier_value_one = replier_df.iloc[0]["counts"] |
1331 | | - | top_replier_two = str(replier_df.iloc[1]["unique_values"]) |
1332 | | - | top_replier_value_two = replier_df.iloc[1]["counts"] |
1333 | | - | top_replier_three = str(replier_df.iloc[2]["unique_values"]) |
1334 | | - | top_replier_value_three = replier_df.iloc[2]["counts"] |
1335 | | - | top_replier_four = str(replier_df.iloc[3]["unique_values"]) |
1336 | | - | top_replier_value_four = replier_df.iloc[3]["counts"] |
1337 | | - | top_replier_five = str(replier_df.iloc[4]["unique_values"]) |
1338 | | - | top_replier_value_five = replier_df.iloc[4]["counts"] |
1339 | | - | |
1340 | | - | replier_one = ( |
1341 | | - | str(top_replier_one) |
| 1223 | + | repliers = createPlaceholdeCls() |
| 1224 | + | repliers.replier_one = ( |
| 1225 | + | str(replier_df.iloc[0]["unique_values"]) |
1342 | 1226 | | + ", " |
1343 | | - | + str(top_replier_value_one) |
| 1227 | + | + str(replier_df.iloc[0]["counts"]) |
1344 | 1228 | | + " replies" |
1345 | 1229 | | ) |
1346 | | - | replier_two = ( |
1347 | | - | str(top_replier_two) |
| 1230 | + | |
| 1231 | + | repliers.replier_two = ( |
| 1232 | + | str(replier_df.iloc[1]["unique_values"]) |
1348 | 1233 | | + ", " |
1349 | | - | + str(top_replier_value_two) |
| 1234 | + | + str(replier_df.iloc[1]["counts"]) |
1350 | 1235 | | + " replies" |
1351 | 1236 | | ) |
1352 | | - | replier_three = ( |
1353 | | - | str(top_replier_three) |
| 1237 | + | |
| 1238 | + | repliers.replier_three = ( |
| 1239 | + | str(replier_df.iloc[2]["unique_values"]) |
1354 | 1240 | | + ", " |
1355 | | - | + str(top_replier_value_three) |
| 1241 | + | + str(replier_df.iloc[2]["counts"]) |
1356 | 1242 | | + " replies" |
1357 | 1243 | | ) |
1358 | | - | replier_four = ( |
1359 | | - | str(top_replier_four) |
| 1244 | + | |
| 1245 | + | repliers.replier_four = ( |
| 1246 | + | str(replier_df.iloc[3]["unique_values"]) |
1360 | 1247 | | + ", " |
1361 | | - | + str(top_replier_value_four) |
| 1248 | + | + str(replier_df.iloc[3]["counts"]) |
1362 | 1249 | | + " replies" |
1363 | 1250 | | ) |
1364 | | - | replier_five = ( |
1365 | | - | str(top_replier_five) |
| 1251 | + | |
| 1252 | + | repliers.replier_five = ( |
| 1253 | + | str(replier_df.iloc[3]["counts"]) |
1366 | 1254 | | + ", " |
1367 | | - | + str(top_replier_value_five) |
| 1255 | + | + str(replier_df.iloc[4]["counts"]) |
1368 | 1256 | | + " replies" |
1369 | 1257 | | ) |
1370 | 1258 | | |
1371 | | - | replier_count_df = c_repliers["User id"].unique() |
1372 | | - | replier_length = len(replier_df) |
| 1259 | + | replier_count_df = c_repliers["User ID"].unique() |
1373 | 1260 | | replier_unique = len(replier_count_df) |
1374 | 1261 | | |
1375 | | - | else: |
1376 | | - | pass |
1377 | | - | |
1378 | | - | #print("\n") |
1379 | | - | color_print_green(" [+] Chat archive saved", "") |
1380 | | - | color_print_green(" ⬠Chat statistics", "") |
1381 | | - | color_print_green( |
1382 | | - | " â Number of messages found: ", str(messages_found) |
1383 | | - | ) |
1384 | | - | |
1385 | | - | if chat_type != "Channel": |
1386 | | - | color_print_green( |
1387 | | - | " â Top poster 1: ", str(poster_one) |
1388 | | - | ) |
1389 | | - | color_print_green( |
1390 | | - | " â Top poster 2: ", str(poster_two) |
1391 | | - | ) |
1392 | | - | color_print_green( |
1393 | | - | " â Top poster 3: ", str(poster_three) |
1394 | | - | ) |
1395 | | - | color_print_green( |
1396 | | - | " â Top poster 4: ", str(poster_four) |
1397 | | - | ) |
1398 | | - | color_print_green( |
1399 | | - | " â Top poster 5: ", str(poster_five) |
1400 | | - | ) |
1401 | | - | color_print_green( |
1402 | | - | " â Total unique posters: ", str(unique_active) |
1403 | | - | ) |
1404 | | - | |
1405 | | - | else: |
1406 | | - | pass |
1407 | | - | # timestamp analysis |
1408 | | - | # print(Fore.GREEN |
1409 | | - | # + ' â Number of messages: ' |
1410 | | - | # + Style.RESET_ALL |
1411 | | - | # + str(message_count)) |
1412 | | - | |
1413 | | - | color_print_green( |
1414 | | - | " â Archive saved to: ", str(file_archive) |
1415 | | - | ) |
1416 | | - | |
1417 | | - | if reply_analysis is True: |
1418 | | - | if len(replies_list) > 0: |
1419 | | - | middle_char = "â" |
1420 | | - | if user_replier_list == 0: |
1421 | | - | middle_char = "â" |
1422 | | - | |
1423 | | - | #print("\n") |
1424 | | - | color_print_green(" [+] Replies analysis ", "") |
1425 | | - | color_print_green(" ⬠Chat statistics", "") |
1426 | | - | color_print_green( |
1427 | | - | f" {middle_char} Archive of replies saved to: ", |
1428 | | - | str(reply_file_archive), |
1429 | | - | ) |
1430 | | - | if len(user_replier_list) > 0: |
1431 | | - | color_print_green( |
1432 | | - | " â Active members list who replied to messages, saved to: ", |
1433 | | - | str(reply_memberlist_filename), |
1434 | | - | ) |
1435 | | - | |
1436 | | - | color_print_green( |
1437 | | - | " â Top replier 1: ", str(replier_one) |
1438 | | - | ) |
1439 | | - | color_print_green( |
1440 | | - | " â Top replier 2: ", str(replier_two) |
1441 | | - | ) |
1442 | | - | color_print_green( |
1443 | | - | " â Top replier 3: ", str(replier_three) |
1444 | | - | ) |
1445 | | - | color_print_green( |
1446 | | - | " â Top replier 4: ", str(replier_four) |
1447 | | - | ) |
1448 | | - | color_print_green( |
1449 | | - | " â Top replier 5: ", str(replier_five) |
1450 | | - | ) |
1451 | | - | color_print_green( |
1452 | | - | " â Total unique repliers: ", str(replier_unique) |
1453 | | - | ) |
| 1262 | + | repliers.user_replier_list_len = len(user_replier_list) |
| 1263 | + | repliers.reply_file_archive = str(reply_file_archive) |
| 1264 | + | repliers.reply_memberlist_filename = str(reply_memberlist_filename) |
| 1265 | + | repliers.replier_unique = str(replier_unique) |
| 1266 | + | print_shell("reply_stat", repliers) |
1454 | 1267 | | |
1455 | 1268 | | if forwards_check is True: |
1456 | 1269 | | if forward_count >= 15: |
| skipped 2 lines |
1459 | 1272 | | c_f_stats = value_count.rename_axis( |
1460 | 1273 | | "unique_values" |
1461 | 1274 | | ).reset_index(name="counts") |
1462 | | - | |
1463 | | - | top_forward_one = c_f_stats.iloc[0]["unique_values"] |
1464 | | - | top_value_one = c_f_stats.iloc[0]["counts"] |
1465 | | - | top_forward_two = c_f_stats.iloc[1]["unique_values"] |
1466 | | - | top_value_two = c_f_stats.iloc[1]["counts"] |
1467 | | - | top_forward_three = c_f_stats.iloc[2][ |
1468 | | - | "unique_values" |
1469 | | - | ] |
1470 | | - | top_value_three = c_f_stats.iloc[2]["counts"] |
1471 | | - | top_forward_four = c_f_stats.iloc[3][ |
1472 | | - | "unique_values" |
1473 | | - | ] |
1474 | | - | top_value_four = c_f_stats.iloc[3]["counts"] |
1475 | | - | top_forward_five = c_f_stats.iloc[4][ |
1476 | | - | "unique_values" |
1477 | | - | ] |
1478 | | - | top_value_five = c_f_stats.iloc[4]["counts"] |
1479 | | - | |
1480 | | - | forward_one = ( |
1481 | | - | str(top_forward_one) |
1482 | | - | + ", " |
1483 | | - | + str(top_value_one) |
1484 | | - | + " forwarded messages" |
| 1275 | + | report_forward = createPlaceholdeCls() |
| 1276 | + | report_forward.forward_one = ( |
| 1277 | + | str(c_f_stats.iloc[0]["unique_values"]) |
| 1278 | + | + ", " |
| 1279 | + | + str(c_f_stats.iloc[0]["counts"]) |
| 1280 | + | + " forwarded messages" |
1485 | 1281 | | ) |
1486 | | - | forward_two = ( |
1487 | | - | str(top_forward_two) |
1488 | | - | + ", " |
1489 | | - | + str(top_value_two) |
1490 | | - | + " forwarded messages" |
| 1282 | + | report_forward.forward_two = ( |
| 1283 | + | str(c_f_stats.iloc[1]["unique_values"]) |
| 1284 | + | + ", " |
| 1285 | + | + str(c_f_stats.iloc[1]["counts"]) |
| 1286 | + | + " forwarded messages" |
1491 | 1287 | | ) |
1492 | | - | forward_three = ( |
1493 | | - | str(top_forward_three) |
1494 | | - | + ", " |
1495 | | - | + str(top_value_three) |
1496 | | - | + " forwarded messages" |
| 1288 | + | report_forward.forward_three = ( |
| 1289 | + | str(c_f_stats.iloc[2]["unique_values"]) |
| 1290 | + | + ", " |
| 1291 | + | + str(c_f_stats.iloc[2]["counts"]) |
| 1292 | + | + " forwarded messages" |
1497 | 1293 | | ) |
1498 | | - | forward_four = ( |
1499 | | - | str(top_forward_four) |
1500 | | - | + ", " |
1501 | | - | + str(top_value_four) |
1502 | | - | + " forwarded messages" |
| 1294 | + | report_forward.forward_four = ( |
| 1295 | + | str(c_f_stats.iloc[3]["unique_values"]) |
| 1296 | + | + ", " |
| 1297 | + | + str(c_f_stats.iloc[3]["counts"]) |
| 1298 | + | + " forwarded messages" |
1503 | 1299 | | ) |
1504 | | - | forward_five = ( |
1505 | | - | str(top_forward_five) |
1506 | | - | + ", " |
1507 | | - | + str(top_value_five) |
1508 | | - | + " forwarded messages" |
| 1300 | + | report_forward.forward_five = ( |
| 1301 | + | str(c_f_stats.iloc[4]["unique_values"]) |
| 1302 | + | + ", " |
| 1303 | + | + str(c_f_stats.iloc[4]["counts"]) |
| 1304 | + | + " forwarded messages" |
1509 | 1305 | | ) |
1510 | 1306 | | |
1511 | 1307 | | c_f_unique = c_forwards.Source.unique() |
1512 | | - | unique_forwards = len(c_f_unique) |
1513 | | - | |
1514 | | - | #print("\n") |
1515 | | - | color_print_green(" [+] Edgelist saved", "") |
1516 | | - | color_print_green( |
1517 | | - | " ⬠Forwarded message statistics", "" |
1518 | | - | ) |
1519 | | - | color_print_green( |
1520 | | - | " â Forwarded messages found: ", |
1521 | | - | str(forward_count), |
1522 | | - | ) |
1523 | | - | color_print_green( |
1524 | | - | " â Forwards from active public chats: ", |
1525 | | - | str(forwards_found), |
1526 | | - | ) |
1527 | | - | color_print_green( |
1528 | | - | " â Forwards from private (or now private) chats: ", |
1529 | | - | str(private_count), |
1530 | | - | ) |
1531 | | - | color_print_green( |
1532 | | - | " â Unique forward sources: ", |
1533 | | - | str(unique_forwards), |
1534 | | - | ) |
1535 | | - | color_print_green( |
1536 | | - | " â Top forward source 1: ", str(forward_one) |
1537 | | - | ) |
1538 | | - | color_print_green( |
1539 | | - | " â Top forward source 2: ", str(forward_two) |
1540 | | - | ) |
1541 | | - | color_print_green( |
1542 | | - | " â Top forward source 3: ", |
1543 | | - | str(forward_three), |
1544 | | - | ) |
1545 | | - | color_print_green( |
1546 | | - | " â Top forward source 4: ", str(forward_four) |
1547 | | - | ) |
1548 | | - | color_print_green( |
1549 | | - | " â Top forward source 5: ", str(forward_five) |
1550 | | - | ) |
1551 | | - | color_print_green( |
1552 | | - | " â Edgelist saved to: ", edgelist_file |
1553 | | - | ) |
1554 | | - | #print("\n") |
1555 | | - | |
| 1308 | + | report_forward.unique_forwards = len(c_f_unique) |
| 1309 | + | report_forward.edgelist_file = edgelist_file |
| 1310 | + | report_forward.private_count = private_count |
| 1311 | + | print_shell("forwarder_stat", report_forward) |
1556 | 1312 | | else: |
1557 | 1313 | | #print("\n") |
1558 | 1314 | | color_print_green( |
| skipped 37 lines |
1596 | 1352 | | user_restrictions = str(ios_restriction) |
1597 | 1353 | | else: |
1598 | 1354 | | user_restrictions = "None" |
1599 | | - | |
1600 | | - | color_print_green(" [+] ", "User details for " + t) |
1601 | | - | color_print_green(" â Username: ", str(my_user.username)) |
1602 | | - | color_print_green(" â Name: ", str(user_full_name)) |
1603 | | - | color_print_green(" â Verification: ", str(my_user.verified)) |
1604 | | - | color_print_green(" â Photo ID: ", str(user_photo)) |
1605 | | - | color_print_green(" â Phone number: ", str(my_user.phone)) |
1606 | | - | color_print_green( |
1607 | | - | " â Access hash: ", str(my_user.access_hash) |
1608 | | - | ) |
1609 | | - | color_print_green(" â Language: ", str(my_user.lang_code)) |
1610 | | - | color_print_green(" â Bot: ", str(my_user.bot)) |
1611 | | - | color_print_green(" â Scam: ", str(my_user.scam)) |
1612 | | - | color_print_green(" â Restrictions: ", str(user_restrictions)) |
| 1355 | + | setattr(my_user, "user_restrictions", str(user_restrictions)) |
| 1356 | + | setattr(my_user, "user_full_name", str(user_full_name)) |
| 1357 | + | setattr(my_user, "user_photo", str(user_photo)) |
| 1358 | + | setattr(my_user, "target", t) |
| 1359 | + | print_shell("user", my_user) |
1613 | 1360 | | |
1614 | 1361 | | except ValueError: |
1615 | 1362 | | pass |
| skipped 70 lines |
1686 | 1433 | | except: |
1687 | 1434 | | pass |
1688 | 1435 | | |
1689 | | - | d_500 = 0 |
1690 | | - | d_1000 = 0 |
1691 | | - | d_2000 = 0 |
1692 | | - | d_3000 = 0 |
| 1436 | + | distance_obj = createPlaceholdeCls() |
| 1437 | + | distance_obj.d500 = 0 |
| 1438 | + | distance_obj.d1000 = 0 |
| 1439 | + | distance_obj.d2000 = 0 |
| 1440 | + | distance_obj.d3000 = 0 |
1693 | 1441 | | |
1694 | 1442 | | for account, distance in user_df.itertuples(index=False): |
1695 | 1443 | | account = int(account) |
| skipped 3 lines |
1699 | 1447 | | distance = int(distance) |
1700 | 1448 | | |
1701 | 1449 | | if distance == 500: |
1702 | | - | d_500 += 1 |
| 1450 | + | distance_obj.d500 += 1 |
1703 | 1451 | | elif distance == 1000: |
1704 | | - | d_1000 += 1 |
| 1452 | + | distance_obj.d1000 += 1 |
1705 | 1453 | | elif distance == 2000: |
1706 | | - | d_2000 += 1 |
| 1454 | + | distance_obj.d2000 += 1 |
1707 | 1455 | | elif distance == 3000: |
1708 | | - | d_3000 += 1 |
| 1456 | + | distance_obj.d3000 += 1 |
1709 | 1457 | | |
1710 | 1458 | | with open( |
1711 | 1459 | | save_file, "w+", encoding="utf-8" |
1712 | | - | ) as f: |
| 1460 | + | ) as f: # could one day append, including access time to differentiate |
1713 | 1461 | | user_df.to_csv(f, sep=";", index=False) |
1714 | 1462 | | |
1715 | 1463 | | total = len(locations_list) |
1716 | | - | |
1717 | | - | color_print_green(" [+] Users located", "") |
1718 | | - | color_print_green(" â Users within 500m: ", str(d_500)) |
1719 | | - | color_print_green(" â Users within 1000m: ", str(d_1000)) |
1720 | | - | color_print_green(" â Users within 2000m: ", str(d_2000)) |
1721 | | - | color_print_green(" â Users within 3000m: ", str(d_3000)) |
1722 | | - | color_print_green(" â Total users found: ", str(total)) |
1723 | | - | color_print_green(" â Location list saved to: ", save_file) |
1724 | | - | |
1725 | | - | user_df.iloc[0:0] |
| 1464 | + | distance_obj.save_file = save_file |
| 1465 | + | distance_obj.total = total |
| 1466 | + | print_shell("location_report",distance_obj) |
| 1467 | + | # can also do the same for channels with similar output file to users |
| 1468 | + | # may one day add trilateration to find users closest to exact point |
1726 | 1469 | | |
1727 | 1470 | | with client: |
1728 | 1471 | | client.loop.run_until_complete(main()) |
| skipped 4 lines |