Skip to content

Commit

Permalink
Create pdf_downloader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gokulapap committed Jun 22, 2021
1 parent 3e336b5 commit 6cd7538
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pdf_downloader/pdf_downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from googlesearch import search


app = Flask(__name__)

@app.route("/pdf", methods=["GET", "POST"])
def reply_whatsapp():
response = MessagingResponse()
body = request.form.get('Body')
query = body.split(';')[1]
query = query + ' filetype:pdf'
pdfs = []
msg = response.message("Fetching Best pdfs for {} ...".format(body.split(';')[1]))

for j in search(query, tld="com", num=5, stop=7, pause=1):
if j[-1:-5:-1] == 'fdp.':
pdfs.append(j)

for i in pdfs:
m = response.message("pdf")
m.media(i)
return str(response)

if __name__ == "__main__":
app.run()

0 comments on commit 6cd7538

Please sign in to comment.