-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathget_chat_location.py
More file actions
36 lines (34 loc) · 1.89 KB
/
Copy pathget_chat_location.py
File metadata and controls
36 lines (34 loc) · 1.89 KB
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
from pyrogram import Client, enums
import access_creds
import os
from pyrogram.errors.exceptions.bad_request_400 import PeerIdInvalid, UsernameInvalid, UsernameNotOccupied, ChatAdminRequired
import sys
app = Client('my_session', api_id=access_creds.api_id, api_hash=access_creds.api_hash)
locations_list = []
def Search_locations():
try:
chat_creds = input('Enter correct numeric chat ID or chat username: ')
try:
with app:
print('\n\033[1;90mGetting information...\n\033[1;00m')
for message in app.search_messages(chat_id=chat_creds, filter=enums.MessagesFilter.LOCATION):
print('\033[1;94m' + message.date.strftime('%Y-%m-%d %H:%M:%S') + '\033[1;00m from user ID: \033[1;94m' + str(message.from_user.id) + '\033[00m')
locations_list.append(message.date.strftime('%Y-%m-%d %H:%M:%S') + ' from user ID: ' + str(message.from_user.id))
locations_list.append(message.location)
except AttributeError:
print('')
with open("Telegram_scan_results.txt", 'a') as output:
output.write('CHAT (id = {}) LOCATIONS => \n'.format(chat_creds))
for row in locations_list:
output.write(str(row) + '\n')
if len(locations_list) == 0:
print('There are no locations one can get.')
else:
print('\nTotal amount of locations is \033[1;94m{}'.format(int(len(locations_list)/2)))
print('\033[1;00mOne can find scan results in \033[1;95m{}/Telegram_scan_results.txt\033[1;00m file'.format(os.getcwd()))
except ChatAdminRequired:
print('\033[1;93mChat Admin permissions required!\033[1;00m')
except (PeerIdInvalid, UsernameInvalid, UsernameNotOccupied, IndexError, TypeError):
print('\033[1;91mNot correct input or smth went wrong!\033[1;00m')
except KeyboardInterrupt:
sys.exit("\n")