Skip to content

Commit

Permalink
🐛 load from url to file and ✨ send report file
Browse files Browse the repository at this point in the history
  • Loading branch information
justadoll committed Nov 22, 2021
1 parent c1cd2b5 commit 3a00742
Show file tree
Hide file tree
Showing 3 changed files with 28,705 additions and 4 deletions.
22 changes: 18 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import logging
import re
import re, os

import maigret
from maigret.result import QueryStatus
from maigret.sites import MaigretDatabase
from maigret.report import save_pdf_report, generate_report_context
from telethon.sync import TelegramClient, events

API_ID = os.getenv('API_ID')
API_HASH = os.getenv('API_HASH')

MAIGRET_DB_URL = 'https://raw.githubusercontent.com/soxoj/maigret/main/maigret/resources/data.json'
MAIGRET_DB_FILE = 'data.json' # wget https://raw.githubusercontent.com/soxoj/maigret/main/maigret/resources/data.json
COOKIES_FILE = "cookies.txt" # wget https://raw.githubusercontent.com/soxoj/maigret/main/cookies.txt
id_type = "username"
USERNAME_REGEXP = r'^[a-zA-Z0-9-_\.]{5,}$'
ADMIN_USERNAME = '@soxoj'

Expand All @@ -31,14 +34,16 @@ async def maigret_search(username):
"""
logger = setup_logger(logging.WARNING, 'maigret')

db = MaigretDatabase().load_from_url(MAIGRET_DB_URL)
db = MaigretDatabase().load_from_path(MAIGRET_DB_FILE)

sites = db.ranked_sites_dict(top=TOP_SITES_COUNT)

results = await maigret.search(username=username,
site_dict=sites,
timeout=TIMEOUT,
logger=logger,
id_type=id_type,
cookies=COOKIES_FILE,
)
return results

Expand Down Expand Up @@ -82,6 +87,10 @@ async def search(username):
return ['An error occurred, send username once again.'], []

found_exact_accounts = []
general_results = []
general_results.append((username, id_type, results))
report_context = generate_report_context(general_results)
save_pdf_report(f"{username}_report.pdf", report_context)

for site, data in results.items():
if data['status'].status != QueryStatus.CLAIMED:
Expand Down Expand Up @@ -115,7 +124,7 @@ async def search(username):
bot_logger.info('I am started.')

with TelegramClient('name', API_ID, API_HASH) as client:
@client.on(events.NewMessage())
@client.on(events.NewMessage(chats=(['kurashh'])))
async def handler(event):
msg = event.message.message

Expand Down Expand Up @@ -146,6 +155,11 @@ async def handler(event):
for output_message in output_messages:
try:
await event.reply(output_message)
filename = f"{msg}_report.pdf"
bot_logger.info(f"{filename=}")
if(os.path.isfile(filename)):
async with client.action(event.from_id, 'document') as action:
await client.send_file(event.from_id, filename, progress_callback=action.progress)
except Exception as e:
bot_logger.error(e, exc_info=True)
await event.reply('Unexpected error has been occurred. '
Expand Down
13 changes: 13 additions & 0 deletions cookies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# HTTP Cookie File downloaded with cookies.txt by Genuinous @genuinous
# This file can be used by wget, curl, aria2c and other standard compliant tools.
# Usage Examples:
# 1) wget -x --load-cookies cookies.txt "https://pixabay.com/users/blue-156711/"
# 2) curl --cookie cookies.txt "https://pixabay.com/users/blue-156711/"
# 3) aria2c --load-cookies cookies.txt "https://pixabay.com/users/blue-156711/"
#
.pixabay.com TRUE / TRUE 1618356838 __cfduid d56929cd50d11474f421b849df5758a881615764837
.pixabay.com TRUE / TRUE 1615766638 __cf_bm ea8f7c565b44d749f65500f0e45176cebccaeb09-1615764837-1800-AYJIXh2boDJ6HPf44JI9fnteWABHOVvkxiSccACP9EiS1E58UDTGhViXtqjFfVE0QRj1WowP4ss2DzCs+pW+qUc=
pixabay.com FALSE / FALSE 0 anonymous_user_id c1e4ee09-5674-4252-aa94-8c47b1ea80ab
pixabay.com FALSE / FALSE 1647214439 csrftoken vfetTSvIul7gBlURt6s985JNM18GCdEwN5MWMKqX4yI73xoPgEj42dbNefjGx5fr
pixabay.com FALSE / FALSE 1647300839 client_width 1680
pixabay.com FALSE / FALSE 748111764839 is_human 1
Loading

0 comments on commit 3a00742

Please sign in to comment.