First commit
This commit is contained in:
34
bot/Dockerfile
Normal file
34
bot/Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
||||
FROM python:3.9
|
||||
|
||||
# Adding trusting keys to apt for repositories
|
||||
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
|
||||
|
||||
# Adding Google Chrome to the repositories
|
||||
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
|
||||
|
||||
# Updating apt to see and install Google Chrome
|
||||
RUN apt-get -y update
|
||||
|
||||
# Magic happens
|
||||
RUN apt-get install -y google-chrome-stable
|
||||
|
||||
# Installing Unzip
|
||||
RUN apt-get install -yqq unzip
|
||||
|
||||
# Download the Chrome Driver
|
||||
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
|
||||
|
||||
# Unzip the Chrome Driver into /usr/local/bin directory
|
||||
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
|
||||
|
||||
# Set display port as an environment variable
|
||||
ENV DISPLAY=:99
|
||||
|
||||
RUN mkdir /app
|
||||
ADD requirements.txt /app
|
||||
ADD *.py /app/
|
||||
RUN pip install -r /app/requirements.txt
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD [ "python", "/app/bot.py" ]
|
||||
30
bot/bot.py
Normal file
30
bot/bot.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium import webdriver
|
||||
from telegram import Update, ForceReply
|
||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
|
||||
|
||||
def get_chrome_options():
|
||||
chrome_options = Options()
|
||||
chrome_options.add_argument("--headless")
|
||||
chrome_options.add_argument("--no-sandbox")
|
||||
chrome_options.add_argument("--disable-dev-shm-usage")
|
||||
chrome_prefs = {}
|
||||
chrome_options.experimental_options["prefs"] = chrome_prefs
|
||||
chrome_prefs["profile.default_content_settings"] = {"images": 2}
|
||||
return chrome_options
|
||||
|
||||
def send_message(message):
|
||||
driver = webdriver.Chrome(options=get_chrome_options())
|
||||
driver.set_window_size(1280, 720)
|
||||
driver.get("https://web.whatsapp.com/")
|
||||
driver.save_screenshot('/data/screenshot.png')
|
||||
#soup = BeautifulSoup(driver.page_source, "lxml"))
|
||||
driver.close()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
send_message("asdf")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
6
bot/requirements.txt
Normal file
6
bot/requirements.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
python-telegram-bot==13.13
|
||||
requests==2.28.1
|
||||
beautifulsoup4==4.11.1
|
||||
lxml==4.9.1
|
||||
selenium==4.4.0
|
||||
Pillow==9.2.0
|
||||
Reference in New Issue
Block a user