Skip to content

Commit

Permalink
fix: dockerfile, handle some extra errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DebXD committed Dec 25, 2022
1 parent c5fad71 commit e20c949
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
FROM python:3.10
WORKDIR /bot
COPY requirements.txt /bot/
FROM ubuntu:latest

RUN apt update
RUN apt install python3 -y
RUN apt install python3-pip -y

WORKDIR /usr/app/src

COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . /bot
CMD python bot.py

ENV BOT_TOKEN=ENTER_YOUR_BOT_TOKEN__
COPY . /usr/app/src
CMD python3 bot.py
39 changes: 22 additions & 17 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from url_validator import isValidURL

BOT_TOKEN = config("BOT_TOKEN")
if BOT_TOKEN is None:
print("Enter Your Bot Token in .env file.")
bot = telebot.TeleBot(BOT_TOKEN)


Expand All @@ -29,24 +31,27 @@ def textToSpeech(message):
else:
link = modified_url[0]
print(link)
bot.reply_to(message, "Ok, Processing...")
title , content = getArticleContent(link)
print("scraping complete")

result = tts(title, content)
bot.reply_to(message, "Ok, Processing...it might take sometime")
wholeText = getArticleContent(link)
if wholeText is not None:
title, content = wholeText
print("scraping complete")
result = tts(title, content)

if result == True:

chat_id = message.chat.id


audio = open("audio.mp3", 'rb')
#bot.send_audio(chat_id, audio)
bot.send_audio(chat_id, audio, performer='Article Reader', title=title)
print("Sent successfully")
audio.close()
if True:
os.remove("audio.mp3")
if result == True:

chat_id = message.chat.id


audio = open("audio.mp3", 'rb')
#bot.send_audio(chat_id, audio)
bot.send_audio(chat_id, audio, performer='Article Reader', title=title)
print("Sent successfully")
audio.close()
if True:
os.remove("audio.mp3")
else:
bot.reply_to(message, "Sorry, failure converting text to audio")

else:
bot.reply_to(message, "Sorry, Can't Process this Article")
Expand Down
26 changes: 18 additions & 8 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@


def getArticleContent(url):
if HTTP_PROXY is not None and HTTPS_PROXY is not None:
article = Article(url, proxies={
"http": HTTP_PROXY,
"https": HTTPS_PROXY })
try:
article = Article(url)
article.download()
except Exception as e:
print(e)
if HTTP_PROXY != None and HTTPS_PROXY != None:
try:
article = Article(url, proxies={
"http": HTTP_PROXY,
"https": HTTPS_PROXY })
article.download()
except Exception as e:
return None
else:
return None

article = Article(url)
article.download()
article.parse()
title = article.title
content = article.text
return title, content




from gtts import gTTS
def tts(title, content):
if True:
try:
tts = gTTS(title +"."+ content)
tts.save("audio.mp3")
return True
except:
print("try again...")
print("try again...TTS")
return False

0 comments on commit e20c949

Please sign in to comment.