SHARE
TWEET

Untitled

a guest Nov 14th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. from  psycopg2 import connect
  3.  
  4. cors = connect(user='jungal01', dbname='course')
  5. req = connect(user="jungal01", dbname='requirement')
  6.  
  7. core = cors.cursor()
  8. reqs = req.cursor()
  9.  
  10. with open('gened.json') as gens:
  11.     geneds = json.load(gens)
  12.  
  13. for i in range(len(geneds)):
  14.     core.execute('''insert into course (number, description, title)
  15.                     values({0}, {1}, {2});''' .format(geneds[i]["number"], geneds[i]['description'], geneds[i]['title'] ))
  16.  
  17. reqs.execute('''insert into requirement (fulfills)
  18.                 values({0});''' .format(geneds[i]['fulfills'] ))
  19. db.commit()
  20.    
  21. import json
  22. from  psycopg2 import connect
  23.  
  24. username = 'jungal01'
  25. conn = connect(dbname=username, user=username)
  26. cur = conn.cursor()
  27.  
  28. with open('gened.json') as gens:
  29.     geneds = json.load(gens)
  30.  
  31.     for g in geneds:
  32.         cur.execute('''insert into course (number, description, title)
  33.                         values(%(number)s, %(description)s, %(title)s);''', g)
  34.  
  35.         cur.execute('''insert into requirement (fulfills)
  36.                     values(%(fulfills)s);''', g)
  37.     conn.commit()
RAW Paste Data
Top