Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import psycopg2
  2.  
  3. from django.conf import settings
  4. wells = WellMapping.objects.filter(decommissioned=False, excluded=False, source__name='InSpatial', foreign_pk__isnull=False)
  5. old_wells = []
  6. for w in wells:
  7.     r = Reading.objects.filter(well_map=w).last()
  8.     if r:
  9.         diff = timezone.now() - r.timestamp
  10.         if diff.days > 0:
  11.             old_wells.append(w)
  12. connection = psycopg2.connect(database=settings.INSPATIAL_DB,
  13.                                   user=settings.INSPATIAL_USER,
  14.                                   password=settings.INSPATIAL_PASSWORD,
  15.                                   host=settings.INSPATIAL_HOST,
  16.                                   port=settings.INSPATIAL_PORT)
  17. cursor = connection.cursor()
  18. for w in old_wells:
  19.     r = Reading.objects.filter(well_map=w).last()
  20.     if r:
  21.         query = 'SELECT max(created_on) FROM exps.asset_measurements_t WHERE asset_id = {};'.format(w.foreign_pk)
  22.         cursor.execute(query)
  23.         date = cursor.fetchone()
  24.         print '%s; %s; %s' % (w.name, r.timestamp, date)
  25.  
  26. cursor.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement