Skip to content

Instantly share code, notes, and snippets.

@BenjaminRosell
Created December 12, 2024 15:44
Show Gist options
  • Save BenjaminRosell/70373f7fd56a0dfa3aa7133bb66841dd to your computer and use it in GitHub Desktop.
Save BenjaminRosell/70373f7fd56a0dfa3aa7133bb66841dd to your computer and use it in GitHub Desktop.
import json
import os
import psycopg2
from pymongo import MongoClient
conn_str = os.getenv('TS_CONNECTION_US')
def get_mapping():
# Load the store mapping from the JSON file
with open("stores.json") as f:
store_mappings = json.load(f)
crc_lookup = {}
for store in store_mappings:
for point in store["points"]:
crc_lookup[point["crc"]] = point["name"]
return crc_lookup
stores = ["savemart_048oakdale", "savemart_49modesto", "savemart_612redding", "savemart_623sacramento",
"savemart_001modesto", "hilltopsupermarket_clarksville", "hghill_springfield", "naturalgrocers_brighton170", "grifols_warehouse01",
"mdsfoods_tullahoma", "cashsaver_ashlandcitymain", "heinens_020strongsville", "heinens_019hudson", "heinens_017brecksville"]
def get_missing_sensors(store_name):
master_keys = []
try:
conn = psycopg2.connect(conn_str)
query = f"""
SELECT DISTINCT master_key
FROM {store_name}.sensors
WHERE master_key NOT IN (
SELECT DISTINCT master_key
FROM {store_name}.sensors
WHERE time >= NOW() - INTERVAL '24 HOURS'
) AND time >= NOW() - INTERVAL '14 DAYS';
"""
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
master_keys = [row[0] for row in result]
except Exception as e:
print(f"Error migrating schema {store_name}: {e}")
finally:
if conn:
conn.close()
return master_keys
def main():
mapping = get_mapping()
for store_name in stores:
sensors = get_missing_sensors(store_name)
print(f"There are {len(sensors)} applications missing for store {store_name}")
for sensor in sensors:
print(f"Sensor CRC: {sensor} => {mapping.get(sensor)}")
print(f"----------------------END OF STORE {store_name}-----------------------------")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment