-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
85 lines (57 loc) · 2.84 KB
/
settings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
import logging
import os
from pymongo import MongoClient
import pytz
from utils import read_json
ENVIRONMENT = os.environ.get('ENVIRONMENT','prod')
logging.info(f"Environment : {ENVIRONMENT}")
logging.info(f"Loading .env file")
from dotenv import load_dotenv
load_dotenv()
MONGO_CONNECTION = os.environ['MONGO_CONNECTION']
CONTACTACTS_DB = os.environ['CONTACTACTS_DB']
CONTACTS_COLLECTION = os.environ['CONTACTS_COLLECTION']
LINKS_COLLECTION = os.environ['LINKS_COLLECTION']
INDUSTRIES_COLLECTION = os.environ['INDUSTRIES_COLLECTION']
SYNC_M_COLLECTION = os.environ['SYNC_M_COLLECTION']
N_LINKS_TO_SKIP_LINKS_SCROLL = int(os.environ.get('N_LINKS_TO_SKIP_LINKS_SCROLL',50))
logging.info(f"Mongo connection: {MONGO_CONNECTION}")
db= MongoClient(MONGO_CONNECTION)[CONTACTACTS_DB]
contacts_collection = db[CONTACTS_COLLECTION]
links_collection = db[LINKS_COLLECTION]
sync_management_collection = db[SYNC_M_COLLECTION]
industries_collection = db[INDUSTRIES_COLLECTION]
def check_index_existence(db,collection_name,*fields ):
for _,value in db[collection_name].index_information().items():
if len(value['key'])!= len(fields):
continue
not_match = False
for vfield,direction in value['key']:
if vfield not in fields:
not_match = True
break
if not_match == False:
return True
return False
if not check_index_existence(db,LINKS_COLLECTION,"link"):
links_collection.create_index("link",unique=True)
if not check_index_existence(db,CONTACTS_COLLECTION,"place_id"):
contacts_collection.create_index("place_id",unique=True)
if not check_index_existence(db,CONTACTS_COLLECTION,"link"):
contacts_collection.create_index("link",unique=True)
# if not check_index_existence(db,RESOURCES_COLLECTION,"az_id"):
# db[RESOURCES_COLLECTION].create_index("az_id",unique=True)
# if not check_index_existence(db,RESOURCES_COLLECTION,"rocket_id"):
# db[RESOURCES_COLLECTION].create_index("rocket_id",unique=True,\
# partialFilterExpression={"rocket_id":{"$type":"string"}})
# if not check_index_existence(db,RESOURCES_COLLECTION,"rocket_id"):
# db[RESOURCES_COLLECTION].create_index("rocket_id",unique=True,\
# partialFilterExpression={"rocket_id":{"$type":"string"}})
# if not check_index_existence(db,RESOURCE_GROUPS_COLLECTION,"az_id"):
# db[RESOURCE_GROUPS_COLLECTION].create_index("az_id",unique=True)
# if not check_index_existence(db,RESOURCE_GROUPS_COLLECTION,"az_id"):
# db[RESOURCE_GROUPS_COLLECTION].create_index("az_id",unique=True)
# if not check_index_existence(db,SUBSCRIPTIONS_COLLECTION,"subscription_id"):
# db[SUBSCRIPTIONS_COLLECTION].create_index("subscription_id",unique=True)
# if not check_index_existence(db,SUBSCRIPTIONS_COLLECTION,"subscription_id"):
# db[SUBSCRIPTIONS_COLLECTION].create_index("subscription_id",unique=True)