-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.py
More file actions
56 lines (45 loc) · 1.54 KB
/
background.py
File metadata and controls
56 lines (45 loc) · 1.54 KB
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
import psycopg2
from psycopg2.extras import DictCursor
from elastic import Elastic
from config import Config
import security, nft_util
import os, datetime, time
# env = {'DEV', 'LIVE'}
luksense_env = 'DEV'
if luksense_env == 'LIVE':
db_url = 'postgres://127.0.0.1:5432/mainnet'
else:
db_url = 'postgres://127.0.0.1:5432/testnet'
conf = Config(luksense_env, db_url)
index_name = conf.get('index_name')
def auto_poster(base_path, nft_id):
upload_dir = os.path.join(conf.get('storage_location'),
datetime.date.today().strftime('%y%m'),
datetime.date.today().strftime('%d'))
print(upload_dir)
if not os.path.isdir(upload_dir):
os.makedirs(upload_dir)
file_list = os.listdir(base_path)
print(file_list)
owner = nft_util.get_nft_owner_cron(nft_id, cur)
print(owner)
if security.can_upload_file_cron(owner, nft_id, len(file_list), cur):
for file in file_list:
source_path = os.path.join(base_path, file)
print(source_path)
res = nft_util.upload_and_process_path_cron(source_path, upload_dir, nft_id, es, cur)
print(res)
s = os.path.getsize(source_path)/(1024*1024)
print(s)
time.sleep(s)
else:
print('cannot upload')
conn = psycopg2.connect(db_url, cursor_factory=DictCursor)
conn.autocommit = True
cur = conn.cursor()
es = Elastic(index_name=index_name)
# RUN HERE
auto_poster('/user/share/luksense/auto', 0)
cur.close()
conn.close()
print('CRON FINISHED')