Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1.  
  2.  
  3. def x():
  4. import pg8000
  5. from getaround.core import models
  6. from getaround.servers.internal.mapreduce import stripe_export
  7. from getaround.servers.internal.mapreduce import core_table_export
  8. import stripe
  9. stripe.api_key = 'sk_live_Z5dWIgshGSE0RaWZPCztUoGV'
  10.  
  11. from getaround.servers.internal.mapreduce.common import postgres_config
  12.  
  13.  
  14. conn = pg8000.connect(user=postgres_config.PgConfig.USER, host=postgres_config.PgConfig.HOST,
  15. port=postgres_config.PgConfig.PORT, database=postgres_config.PgConfig.DATABASE,
  16. password=postgres_config.PgConfig.PASSWORD, ssl=postgres_config.PgConfig.SSL)
  17. cursor = conn.cursor()
  18.  
  19. sql = """
  20. WITH receipt_item_rental_ids AS (
  21. SELECT rental_id FROM public.receipt_item
  22. )
  23. SELECT rental.id
  24. FROM public.rental
  25. LEFT JOIN receipt_item_rental_ids ON rental.id = receipt_item_rental_ids.rental_id
  26. WHERE modified > '2016/01/01' AND receipt_item_rental_ids.rental_id IS NULL
  27. """
  28. cursor.execute(sql)
  29. results = cursor.fetchall()
  30.  
  31. with open('/Users/xcheng/Downloads/fix_it.txt', 'w+') as outf:
  32. for row in results:
  33. rental_id = row[0]
  34.  
  35. print "redoing export for rental %s " % rental_id
  36.  
  37. rental = models.Rental.get_by(id=long(rental_id))
  38. request = rental.request.get_subject()
  39. for stmt in core_table_export.core_entity_map(request):
  40. outf.write((stmt+"\n").encode("utf-8"))
  41.  
  42. cursor.close()
  43. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement