■ ■ ■ ■ ■ ■
src/commands/totalcomments/run.py
| 1 | + | import yaml |
| 2 | + | import readline |
| 3 | + | import signal |
| 4 | + | from prettytable import PrettyTable |
| 5 | + | from src import printcolors as pc |
| 6 | + | from src import utils as utils |
| 7 | + | import json |
| 8 | + | import sys |
| 9 | + | import time |
| 10 | + | |
| 11 | + | from src.CommandFather import CommandFather |
| 12 | + | |
| 13 | + | |
| 14 | + | class Command(CommandFather): |
| 15 | + | |
| 16 | + | def __init__(self, status, api): |
| 17 | + | super().__init__(status) |
| 18 | + | self.status = status |
| 19 | + | self.osintgram = api |
| 20 | + | |
| 21 | + | def run(self): |
| 22 | + | if self.osintgram.check_private_profile(): |
| 23 | + | return |
| 24 | + | |
| 25 | + | pc.printout("Searching for " + self.osintgram.target + " total comments...\n") |
| 26 | + | |
| 27 | + | comment_counter = 0 |
| 28 | + | posts = 0 |
| 29 | + | |
| 30 | + | data = [] |
| 31 | + | result = self.osintgram.get_api().user_feed(str(self.osintgram.target_id)) |
| 32 | + | data.extend(result.get('items', [])) |
| 33 | + | |
| 34 | + | next_max_id = result.get('next_max_id') |
| 35 | + | while next_max_id: |
| 36 | + | if(int(super().get_option('output_limit')) > 0 and len(data) > int(super().get_option('output_limit'))): |
| 37 | + | break |
| 38 | + | |
| 39 | + | if(int(super().get_option('delay')) > 0): |
| 40 | + | time.sleep(int(super().get_option('delay'))) |
| 41 | + | |
| 42 | + | results = self.osintgram.get_api().user_feed(str(self.osintgram.target_id), max_id=next_max_id) |
| 43 | + | data.extend(results.get('items', [])) |
| 44 | + | next_max_id = results.get('next_max_id') |
| 45 | + | |
| 46 | + | for post in data: |
| 47 | + | if(int(super().get_option('output_limit')) > 0 and posts == int(super().get_option('output_limit'))): |
| 48 | + | break |
| 49 | + | |
| 50 | + | comment_counter += post['comment_count'] |
| 51 | + | posts += 1 |
| 52 | + | |
| 53 | + | output = { |
| 54 | + | 'comment_counter': comment_counter, |
| 55 | + | 'posts': posts |
| 56 | + | } |
| 57 | + | |
| 58 | + | self.status.print_output([output], ['Comments', 'Posts'], ['comment_counter', 'posts']) |