#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from pyrogram import Client, filters
from pyrogram.errors import FloodWait
import sqlite3
app = Client("my_account")
con = sqlite3.connect('users.db')
cur = con.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS `all` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
`tg_id` text(20) NOT NULL,
`username` text(255) NOT NULL,
`first_name` text(255) NOT NULL,
`last_name` text(255) DEFAULT NULL)
''')
con.commit()
with app:
for dialogs in app.iter_dialogs():
if dialogs.chat.type == "private":
tg_id = str(dialogs.chat.id)
username = dialogs.chat.username
first_name = dialogs.chat.first_name
last_name = dialogs.chat.last_name
dialog = (tg_id,username,first_name,last_name)
cur.executemany('INSERT INTO all(tg_id,username,first_name,last_name) VALUES(?,?,?,?);', dialog)
con.commit()
cur.execute("SELECT * FROM all")
all_results = cur.fetchall()
print(all_results)
print(1)
app.run()