Skip to content

Instantly share code, notes, and snippets.

@alyx
Created February 22, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alyx/9161229 to your computer and use it in GitHub Desktop.
Save alyx/9161229 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
import csv, psycopg2, sys
conn = psycopg2.connect(database="pokedex", user="pokedex", password="pokedex17984", host="meth.guru")
def berries():
print(" Importing Berries")
cur = conn.cursor()
cur.execute("CREATE TABLE berries (id int, item_id int, firmness_id int, natural_gift_power int, natural_gift_type_id int, size int, max_harvest int, growth_time int, soil_dryness int, smoothness int, PRIMARY KEY(id));")
f = open("../berries.csv", "rb")
d = csv.DictReader(f)
to_db = [(i["id"], i["item_id"], i["firmness_id"], i["natural_gift_power"], i["natural_gift_type_id"], i["size"], i["max_harvest"], i["growth_time"], i["soil_dryness"], i["smoothness"]) for i in d]
cur.executemany("INSERT INTO berries (id, item_id, firmness_id, natural_gift_power, natural_gift_type_id, size, max_harvest, growth_time, soil_dryness, smoothness) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);", to_db)
conn.commit()
berries()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment