Skip to content

Commit 268c844

Browse files
author
Alexandru Meterez
committed
Fix multiple proxy launching issue
1 parent 2422e7a commit 268c844

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

fred/data/collect.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import time
55
import json
66
import base64
7-
from browsermobproxy import Server
8-
from pprint import pprint
7+
from run import proxy
98

109
SCRIPT = """var body = document.body,
1110
html = document.documentElement;
@@ -45,9 +44,7 @@ def collect_data(url, output_folder, output_filename):
4544
output_folder = os.path.join("./tmp", output_folder)
4645
if not os.path.exists(output_folder):
4746
os.mkdir(output_folder)
48-
server = Server("utils/browsermob_proxy/bin/browsermob-proxy", options={'port': 8090})
49-
server.start()
50-
proxy = server.create_proxy()
47+
5148
options = webdriver.ChromeOptions()
5249
options.add_argument("--start-maximized")
5350
options.add_argument("--force-device-scale-factor=2")
@@ -81,4 +78,3 @@ def collect_data(url, output_folder, output_filename):
8178
f.write(png)
8279
driver.execute_script("window.scrollTo(0, 0)")
8380
driver.close()
84-
server.stop()

fred/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from endpoints.get_result import Result
99
from apscheduler.schedulers.background import BackgroundScheduler
1010
from flask import Flask, request, send_from_directory
11+
from browsermobproxy import Server
1112

1213

1314
def clear_ended():
@@ -32,16 +33,16 @@ def after_request(response):
3233
response.headers["Expires"] = 0
3334
response.headers["Pragma"] = "no-cache"
3435
return response
35-
36+
server = Server("utils/browsermob_proxy/bin/browsermob-proxy", options={'port': 8090})
37+
server.start()
38+
proxy = server.create_proxy()
3639
cors = CORS(app, resources={r"*": {"origins": "*"}})
3740
api = Api(app)
3841
api.add_resource(Verify, "/api/verify")
3942
api.add_resource(IDList, "/api/ids")
4043
api.add_resource(Shutdown, "/api/shutdown")
4144
api.add_resource(Result, "/api/result")
42-
# scheduler = BackgroundScheduler()
43-
# scheduler.add_job(func=clear_ended, trigger='interval', seconds=300)
44-
# scheduler.start()
4545

4646
if __name__ == '__main__':
4747
app.run(host='0.0.0.0', debug=True)
48+
server.stop()

0 commit comments

Comments
 (0)