Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def x():
- import pg8000
- from getaround.core import models
- from getaround.servers.internal.mapreduce import stripe_export
- from getaround.servers.internal.mapreduce import core_table_export
- import stripe
- stripe.api_key = 'sk_live_Z5dWIgshGSE0RaWZPCztUoGV'
- from getaround.servers.internal.mapreduce.common import postgres_config
- conn = pg8000.connect(user=postgres_config.PgConfig.USER, host=postgres_config.PgConfig.HOST,
- port=postgres_config.PgConfig.PORT, database=postgres_config.PgConfig.DATABASE,
- password=postgres_config.PgConfig.PASSWORD, ssl=postgres_config.PgConfig.SSL)
- cursor = conn.cursor()
- sql = """
- WITH receipt_item_rental_ids AS (
- SELECT rental_id FROM public.receipt_item
- )
- SELECT rental.id
- FROM public.rental
- LEFT JOIN receipt_item_rental_ids ON rental.id = receipt_item_rental_ids.rental_id
- WHERE modified > '2016/01/01' AND receipt_item_rental_ids.rental_id IS NULL
- """
- cursor.execute(sql)
- results = cursor.fetchall()
- with open('/Users/xcheng/Downloads/fix_it.txt', 'w+') as outf:
- for row in results:
- rental_id = row[0]
- print "redoing export for rental %s " % rental_id
- rental = models.Rental.get_by(id=long(rental_id))
- request = rental.request.get_subject()
- for stmt in core_table_export.core_entity_map(request):
- outf.write((stmt+"\n").encode("utf-8"))
- cursor.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement