-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (61 loc) · 1.99 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
from itertools import product
import logging
from webscraper.models.tasks import TaskModel
from webscraper.models.products import ProductModel
from webscraper.flask import api, app
from webscraper.flask.routes import TaskApi, bp, profile
from webscraper.flask.routes import ProductApi, ProfileApi
from webscraper.flask.monitor import MonitorThread
from webscraper.utility.utils import db, add_to_database, get_from_database
import requests
from flask import Flask
import threading
import time
@app.before_first_request
def activate_job():
logging.info("Starting thread")
thread = MonitorThread()
thread.start()
def start_runner():
def start_loop():
not_started = True
while not_started:
logging.debug("Checking monitor thread status...")
try:
r = requests.get("http://127.0.0.1:5000/")
if r.status_code == 200:
logging.debug("Server started, quiting start_loop...")
not_started = False
logging.debug("Started monitor thread.")
except:
logging.debug("Server not yet started.")
time.sleep(2)
logging.debug("Started runner")
thread = threading.Thread(target=start_loop)
thread.start()
if __name__ == "__main__":
api.add_resource(
ProductApi,
"/api/product",
"/api/product/<int:product_id>",
"/api/products",
"/api/products/<int:product_id>",
)
api.add_resource(
ProfileApi,
"/api/profile",
"/api/profile/<int:id>",
"/api/profiles",
"/api/profiles/<int:id>",
)
# api.add_resource(HistoryApi, "/api/history", "/api/history/<int:id>")
api.add_resource(
TaskApi, "/api/task", "/api/task/<int:id>", "/api/tasks/<int:id>", "/api/tasks"
)
app.register_blueprint(bp)
# mt = MonitorThread()
# mt.run()
# mt = MonitorThread()
# get_from_database(ProductModel)
start_runner()
app.run(host="0.0.0.0")