-
Notifications
You must be signed in to change notification settings - Fork 124
/
get_instant_view.py
48 lines (38 loc) · 1.38 KB
/
get_instant_view.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
import logging
import argparse
from utils import setup_logging
from telegram.client import Telegram
"""
Prints short description of a webpage (using Telegram's instant view)
Usage:
python examples/get_instant_view.py api_id api_hash phone https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5
"""
if __name__ == "__main__":
setup_logging(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument("api_id", help="API id") # https://my.telegram.org/apps
parser.add_argument("api_hash", help="API hash")
parser.add_argument("phone", help="Phone")
parser.add_argument("url", help="Webpage URL")
args = parser.parse_args()
tg = Telegram(
api_id=args.api_id,
api_hash=args.api_hash,
phone=args.phone,
database_encryption_key="changeme1234",
)
# you must call login method before others
tg.login()
# try this for example
# https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5
result = tg.get_web_page_instant_view(
url=args.url,
)
result.wait()
if result.error:
print(f"error: {result.error_info}")
else:
print("Instant view: ")
short_text = result.update["page_blocks"][0]["title"]["text"]
print(f"\n {short_text}")
tg.stop()