aboutsummaryrefslogtreecommitdiffstats
path: root/__main__.py
blob: 95b78ab19ed5a26c720c664a36b5b9065096d77a (plain)
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
# Copyright (c) 2018, George Tokmaji

# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.

# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from .helpers import *
from .handlers import *
from .routes import *
import time
sys.tracebacklimit = 1000

@route("/api")
def get_root():
    notAllowed()

if __name__ == "__main__":
    def loadEntries():
        for handler in [CC(), CCAN()]:
            handler.process()
    
    def checkForUnownedFiles():
        while True:
            session = DBSession()
            for file in session.query(File).filter_by(upload=None):
                if not file.upload and file.date - datetime.now() > 5 * 60:
                    session.delete(file)
                    _unlink_file(file)
            time.sleep(600)
    
    threading.Thread(target=loadEntries, daemon=True).start()
    threading.Thread(target=checkForUnownedFiles, daemon=True).start()
    run(host='0.0.0.0', port=9621, debug=True)