Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from django.conf import settings
- wells = WellMapping.objects.filter(decommissioned=False, excluded=False, source__name='InSpatial', foreign_pk__isnull=False)
- old_wells = []
- for w in wells:
- r = Reading.objects.filter(well_map=w).last()
- if r:
- diff = timezone.now() - r.timestamp
- if diff.days > 0:
- old_wells.append(w)
- connection = psycopg2.connect(database=settings.INSPATIAL_DB,
- user=settings.INSPATIAL_USER,
- password=settings.INSPATIAL_PASSWORD,
- host=settings.INSPATIAL_HOST,
- port=settings.INSPATIAL_PORT)
- cursor = connection.cursor()
- for w in old_wells:
- r = Reading.objects.filter(well_map=w).last()
- if r:
- query = 'SELECT max(created_on) FROM exps.asset_measurements_t WHERE asset_id = {};'.format(w.foreign_pk)
- cursor.execute(query)
- date = cursor.fetchone()
- print '%s; %s; %s' % (w.name, r.timestamp, date)
- cursor.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement