This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
executable file
·51 lines (40 loc) · 1.51 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
#!/usr/bin/env python
import config
from models import *
import input_processor as ip
import output_processor as op
from upload import upload
import os
import glob
import sys
import datetime
# import ipdb; ipdb.set_trace()
def main():
if not os.path.isfile(config.Config().processing_database):
DbActions.create_db()
else:
DbActions.vacuum() # cleans up DB indices for speed
the_filenames = config.Config().filenames_to_process()
print(f'Running report for {config.Config().start_time().isoformat()} to {config.Config().end_time().isoformat()}')
# process the log lines into a sqlite database
print(f'{len(the_filenames)} log file(s) will be added to the database')
print(f'Last processed date: {config.Config().last_processed_on()}')
for lf in the_filenames:
with open(lf) as infile:
print(f'{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} importing {lf}')
for line in infile:
ll = ip.LogLine(line)
ll.populate()
config.Config().update_log_processed_date()
config.Config().copy_db_to_disk()
print('')
DbActions.vacuum() # cleanup indices, etc, maybe makes queries faster
# output for each unique identifier (that isn't robots)
my_report = op.JsonReport()
my_report.output()
if config.Config().upload_to_hub == True:
upload.send_to_datacite()
if 'test_mode' not in globals():
sys.exit(0) # this is causing the tests to fail
if __name__ == '__main__':
main()