-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2895127
Showing
89 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions | ||
|
||
name: Build and deploy Python app to Azure Web App - pwengimagescrap | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python version | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: '3.7' | ||
|
||
- name: Create and start virtual environment | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
# Optional: Add step to run tests here (PyTest, Django test suites, etc.) | ||
|
||
- name: Upload artifact for deployment jobs | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: python-app | ||
path: | | ||
. | ||
!venv/ | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: | ||
name: 'Production' | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: python-app | ||
path: . | ||
|
||
- name: 'Deploy to Azure Web App' | ||
uses: azure/webapps-deploy@v2 | ||
id: deploy-to-webapp | ||
with: | ||
app-name: 'pwengimagescrap' | ||
slot-name: 'Production' | ||
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_217D42C8DFF04DA7B4F63AD17D93911A }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from flask import Flask, render_template, request,jsonify | ||
from flask_cors import CORS,cross_origin | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from urllib.request import urlopen as uReq | ||
import logging | ||
import pymongo | ||
logging.basicConfig(filename="scrapper.log" , level=logging.INFO) | ||
import os | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/", methods = ['GET']) | ||
def homepage(): | ||
return render_template("index.html") | ||
|
||
@app.route("/review" , methods = ['POST' , 'GET']) | ||
def index(): | ||
if request.method == 'POST': | ||
try: | ||
|
||
# query to search for images | ||
query = request.form['content'].replace(" ","") | ||
|
||
# directory to store downloaded images | ||
save_directory = "images/" | ||
|
||
# create the directory if it doesn't exist | ||
if not os.path.exists(save_directory): | ||
os.makedirs(save_directory) | ||
|
||
|
||
|
||
# fake user agent to avoid getting blocked by Google | ||
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"} | ||
|
||
# fetch the search results page | ||
response = requests.get(f"https://www.google.com/search?q={query}&sxsrf=AJOqlzUuff1RXi2mm8I_OqOwT9VjfIDL7w:1676996143273&source=lnms&tbm=isch&sa=X&ved=2ahUKEwiq-qK7gaf9AhXUgVYBHYReAfYQ_AUoA3oECAEQBQ&biw=1920&bih=937&dpr=1#imgrc=1th7VhSesfMJ4M") | ||
|
||
|
||
# parse the HTML using BeautifulSoup | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# find all img tags | ||
image_tags = soup.find_all("img") | ||
|
||
# download each image and save it to the specified directory | ||
del image_tags[0] | ||
img_data=[] | ||
for index,image_tag in enumerate(image_tags): | ||
# get the image source URL | ||
image_url = image_tag['src'] | ||
#print(image_url) | ||
|
||
# send a request to the image URL and save the image | ||
image_data = requests.get(image_url).content | ||
mydict={"Index":index,"Image":image_data} | ||
img_data.append(mydict) | ||
with open(os.path.join(save_directory, f"{query}_{image_tags.index(image_tag)}.jpg"), "wb") as f: | ||
f.write(image_data) | ||
client = pymongo.MongoClient("mongodb+srv://snshrivas:[email protected]/?retryWrites=true&w=majority") | ||
db = client['image_scrap'] | ||
review_col = db['image_scrap_data'] | ||
review_col.insert_many(img_data) | ||
|
||
return "image laoded" | ||
except Exception as e: | ||
logging.info(e) | ||
return 'something is wrong' | ||
# return render_template('results.html') | ||
|
||
else: | ||
return render_template('index.html') | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', port=8000) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
flask | ||
flask_cors | ||
requests | ||
bs4 | ||
pymongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
INFO:werkzeug:[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m | ||
* Running on all addresses (0.0.0.0) | ||
* Running on http://127.0.0.1:5000 | ||
* Running on http://172.18.0.21:5000 | ||
INFO:werkzeug:[33mPress CTRL+C to quit[0m | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:00:41] "GET / HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:00:41] "[36mGET /static/css/style.css HTTP/1.1[0m" 304 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:00:41] "[36mGET /static/css/main.css HTTP/1.1[0m" 304 - | ||
INFO:root:name 'os' is not defined | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:00:44] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m | ||
* Running on all addresses (0.0.0.0) | ||
* Running on http://127.0.0.1:5000 | ||
* Running on http://172.18.0.21:5000 | ||
INFO:werkzeug:[33mPress CTRL+C to quit[0m | ||
INFO:root:name 'BeautifulSoup' is not defined | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:18] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:20] "GET / HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:20] "[36mGET /static/css/main.css HTTP/1.1[0m" 304 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:20] "[36mGET /static/css/style.css HTTP/1.1[0m" 304 - | ||
INFO:root:name 'BeautifulSoup' is not defined | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:23] "POST /review HTTP/1.1" 200 - | ||
INFO:root:name 'BeautifulSoup' is not defined | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:23] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m | ||
* Running on all addresses (0.0.0.0) | ||
* Running on http://127.0.0.1:5000 | ||
* Running on http://172.18.0.21:5000 | ||
INFO:werkzeug:[33mPress CTRL+C to quit[0m | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:52] "GET / HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:52] "[36mGET /static/css/main.css HTTP/1.1[0m" 304 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:52] "[36mGET /static/css/style.css HTTP/1.1[0m" 304 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:52] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.2 - - [21/Feb/2023 23:01:57] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m | ||
* Running on all addresses (0.0.0.0) | ||
* Running on http://127.0.0.1:5000 | ||
* Running on http://172.20.10.9:5000 | ||
INFO:werkzeug:[33mPress CTRL+C to quit[0m | ||
INFO:werkzeug:172.20.10.9 - - [22/Feb/2023 11:24:04] "GET / HTTP/1.1" 200 - | ||
INFO:werkzeug:172.20.10.9 - - [22/Feb/2023 11:24:04] "GET /static/css/main.css HTTP/1.1" 200 - | ||
INFO:werkzeug:172.20.10.9 - - [22/Feb/2023 11:24:04] "GET /static/css/style.css HTTP/1.1" 200 - | ||
INFO:werkzeug:172.20.10.9 - - [22/Feb/2023 11:24:04] "[33mGET /favicon.ico HTTP/1.1[0m" 404 - | ||
INFO:werkzeug:172.20.10.9 - - [22/Feb/2023 11:24:16] "POST /review HTTP/1.1" 200 - | ||
INFO:werkzeug:[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m | ||
* Running on all addresses (0.0.0.0) | ||
* Running on http://127.0.0.1:8000 | ||
* Running on http://172.18.0.84:8000 | ||
INFO:werkzeug:[33mPress CTRL+C to quit[0m | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:24:26] "GET / HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:24:26] "GET /static/css/main.css HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:24:26] "GET /static/css/style.css HTTP/1.1" 200 - | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:24:27] "[33mGET /favicon.ico HTTP/1.1[0m" 404 - | ||
INFO:root:bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'} | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:24:36] "POST /review HTTP/1.1" 200 - | ||
INFO:root:bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'} | ||
INFO:werkzeug:172.18.0.45 - - [27/Jul/2024 16:25:00] "POST /review HTTP/1.1" 200 - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
body, html { | ||
margin: 0; | ||
font-family: sans-serif; | ||
} | ||
|
||
.content { | ||
margin: 0 auto; | ||
width: 400px; | ||
} | ||
|
||
table, td, th { | ||
border: 1px solid #aaa; | ||
} | ||
|
||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
} | ||
|
||
th { | ||
height: 30px; | ||
} | ||
|
||
td { | ||
text-align: center; | ||
padding: 5px; | ||
} | ||
|
||
.form { | ||
margin-top: 20px; | ||
} | ||
|
||
#content { | ||
width: 70%; | ||
} |
Oops, something went wrong.