Esempio n. 1
0
async def save_name_and_url(msg: types.Message, state: FSMContext):
    if msg.text in [i['name'] for i in database.fetchall(msg.from_user.id)]:
        await msg.answer(f"Имя {msg.text} занято придумайте другое")
        await SiteStates.write_name.set()  # FSM.py
    else:
        await state.update_data({"name": msg.text})
        screenshot_detail = await state.get_data()
        await state.finish()
        await msg.answer(
            "Отлично! Вот данные, которые вы ввели:\n\n"
            f"Имя: {screenshot_detail['name']}\n\n"
            f"Url: {screenshot_detail['url']}\n",
            reply_markup=ReplyKeyboardRemove())
        await msg.answer("Подождите делаем скриншот!")
        url, name = screenshot_detail['url'], screenshot_detail['name']
        user = msg.from_user.id
        database.insert({'name': name, 'url': url, 'user': user})
        logger.info(msg.chat.id)
        browser = Browser(url, name)
        try:
            browser.get_sreenshot()
        except InvalidArgumentException:
            await msg.answer("Упс похоже Вы ввели неправильный адресс!",
                             reply_markup=next_button)
        else:
            await msg.answer("Ваш скриншот готов:\n")
            await send_image(msg, screenshot_detail['name'])
            await msg.answer("Выберите:", reply_markup=next_button)
Esempio n. 2
0
 def get_sreenshot(self):  #  Получаем скриншот 1920 x full_height
     self.browser.get(self.url)
     height = self.scroll()
     self.browser.set_window_size(1920, height)
     time.sleep(3)
     logger.info('Browser get screenshot')
     self.browser.save_screenshot(f'./media/{self.name}.png')
     logger.info('Browser quit')
     self.browser.quit()
Esempio n. 3
0
 def __init__(self, url, name):
     self.name = name
     self.url = url
     options = Options()
     options.add_argument('--no-sandbox')
     options.add_argument('--headless')
     options.add_argument('--disable-gpu')
     options.add_argument('--disable-dev-shm-usage')
     self.browser = webdriver.Chrome(executable_path=CHROMADRIVER_PATH,
                                     options=options)
     self.browser.set_window_size(1920, 1080)
     logger.info('browser is created')
Esempio n. 4
0
from typing import Dict, List
import psycopg2
from logging_seting import logger
from main import config

name = config.get('Postgresql', 'db')
user = config.get('Postgresql', 'user')
password = config.get('Postgresql', 'password')
host = config.get('Postgresql', 'host')
conn = psycopg2.connect(database=name,
                        user=user,
                        password=password,
                        host=host,
                        port=5432)
logger.info('Postgresql database opened succsesfuly')
cursor = conn.cursor()


def insert(values: Dict) -> None:
    cursor.execute(
        "INSERT INTO screenshot(name, url, customer) "
        f"VALUES('{values['name']}', '{values['url']}', '{values['user']}');")
    conn.commit()


def delete(row_name: str) -> None:
    cursor.execute(f"DELETE FROM screenshot WHERE name = '{row_name}';")
    conn.commit()


def fetchall(user: str) -> List[Dict]:
Esempio n. 5
0
import configparser
from aiogram import Bot, Dispatcher, executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from logging_seting import logger

config = configparser.ConfigParser()
config.read('config.ini')
TOKEN = config.get("Telegram", "TOKEN")
CHROMADRIVER_PATH = config.get("Chromedriver", "PATH")

bot = Bot(TOKEN, parse_mode="HTML")
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)

if __name__ == '__main__':
    logger.info('bot is running...')
    from handlers import dp
    executor.start_polling(dp)