-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
80 lines (58 loc) · 2.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys, os
if sys.executable.endswith('pythonw.exe'):
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.path.join(os.getenv('TEMP'), 'stderr-{}'.format(os.path.basename(sys.argv[0]))), "w")
from flask import Flask, request, jsonify, render_template
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import util
import random, threading, webbrowser
from flaskwebgui import FlaskUI
# from flask_cors import CORS
global driver
app = Flask(
__name__,
template_folder='templates', # Name of html file folder
static_folder='static' # Name of directory for static files
)
@app.route('/') # What happens when the user visits the site
def base_page():
return render_template(
'app.html', # Template file path, starting from the templates' folder.
)
@app.route('/get_data', methods=['GET', 'POST'])
def grab_data():
image_name = request.form['image_data']
image_num = int(request.form['image_count'])
image_des_folder = request.form['image_destination_folder']
# image_data = image_data.replace(" ", "")
# print(image_data)
# response = jsonify(util.classify_image(image_data))
# print(image_num)
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
print("Connecting...")
# if True:
# send_data(msg="fd")
driver.get("https://unsplash.com")
print("Connected to Unsplash\n")
# destination_folder = r"C:\Users\Debjeet\Desktop\web_scraper\image/"
destination_folder = image_des_folder
response = util.scrap(image_name, image_num, destination_folder, driver)
driver.quit()
print("\n\nDONE...!")
# response = "DONE...!"
# response.headers.add('Access-Control-Allow-Origin', '*')
# time.sleep(4)
return response.replace("\\", "/")
if __name__ == "__main__":
# port = 5000 + random.randint(0, 999)
# url = "http://127.0.0.1:{0}".format(port)
#
# threading.Timer(1.25, lambda: webbrowser.open(url)).start()
print("Starting Python Flask Server")
# app.run()
FlaskUI(app=app, width=925, height=550, server="flask").run()