Created
February 22, 2014 19:53
-
-
Save alyx/9161229 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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