import MySQLdb

# Download Guest List.csv from Facebook event page and copy it to a file named
# 'list.csv'. Remove the first line (column title) and the '"'s around each
# name (they cause trouble with MySQL)
filename = "list.csv"
data = open(filename, 'r');
guests = [];

db_host = "" # Add your host
db_user = "" # Add your user
db_password = "" # Add your password
db_name = "" # Add your database name
db_table = "" # Add your table name

for line in data:
   person = line.split(',')
   guests.append([person[0].strip(), person[1].strip()])

print("Number of guests {}\n".format(str(len(guests))))

db = MySQLdb.connect(db_host, db_user, db_password, db_name)
cursor = db.cursor()

for person, status in guests:
   print("Adding " + person + " status: " + status)
   cursor.execute("INSERT INTO {} (name, status)\
         VALUES (\"{}\", \"{}\")".format(db_table, person, status))

# Clean up
cursor.close()
db.commit()
db.close()

import MySQLdb
import json

# Download Guest List.csv from Facebook event page and copy it to a file named
# 'list.csv'. Remove the first line (column title) and the '"'s around each
# name (they cause trouble with MySQL)
filename = "list.csv"
data = open(filename, 'r')
guests = []

# Config Setup
config_file = open('config.json', 'r')
config = json.load(config_file)

for line in data:
   person = line.split(',')
   guests.append([person[0].strip(), person[1].strip()])

print("Number of guests {}\n".format(str(len(guests))))

db = MySQLdb.connect(config['db_host'], config['db_user'], config['db_password'],
 config['db_name'])
cursor = db.cursor()

for person, status in guests:
   print("Adding " + person + " status: " + status)
   cursor.execute("INSERT INTO {} (name, status)\
         VALUES (\"{}\", \"{}\")".format(db_table, person, status))

# Clean up
cursor.close()
db.commit()
db.close()

Use config file in import script
Use config file in import script

  import MySQLdb
+ import json
  
  # Download Guest List.csv from Facebook event page and copy it to a file named
  # 'list.csv'. Remove the first line (column title) and the '"'s around each
  # name (they cause trouble with MySQL)
  filename = "list.csv"
- data = open(filename, 'r');
+ data = open(filename, 'r')
- guests = [];
+ guests = []
  
+ # Config Setup
+ config_file = open('config.json', 'r')
+ config = json.load(config_file)
- db_host = "" # Add your host
- db_user = "" # Add your user
- db_password = "" # Add your password
- db_name = "" # Add your database name
- db_table = "" # Add your table name
  
  for line in data:
     person = line.split(',')
     guests.append([person[0].strip(), person[1].strip()])
  
  print("Number of guests {}\n".format(str(len(guests))))
  
- db = MySQLdb.connect(db_host, db_user, db_password, db_name)
+ db = MySQLdb.connect(config['db_host'], config['db_user'], config['db_password'],
+  config['db_name'])
  cursor = db.cursor()
  
  for person, status in guests:
     print("Adding " + person + " status: " + status)
     cursor.execute("INSERT INTO {} (name, status)\
           VALUES (\"{}\", \"{}\")".format(db_table, person, status))
  
  # Clean up
  cursor.close()
  db.commit()
  db.close()
  
Use config file in import script
## Code Before:
import MySQLdb

# Download Guest List.csv from Facebook event page and copy it to a file named
# 'list.csv'. Remove the first line (column title) and the '"'s around each
# name (they cause trouble with MySQL)
filename = "list.csv"
data = open(filename, 'r');
guests = [];

db_host = "" # Add your host
db_user = "" # Add your user
db_password = "" # Add your password
db_name = "" # Add your database name
db_table = "" # Add your table name

for line in data:
   person = line.split(',')
   guests.append([person[0].strip(), person[1].strip()])

print("Number of guests {}\n".format(str(len(guests))))

db = MySQLdb.connect(db_host, db_user, db_password, db_name)
cursor = db.cursor()

for person, status in guests:
   print("Adding " + person + " status: " + status)
   cursor.execute("INSERT INTO {} (name, status)\
         VALUES (\"{}\", \"{}\")".format(db_table, person, status))

# Clean up
cursor.close()
db.commit()
db.close()

## Instruction:
Use config file in import script
## Code After:
import MySQLdb
import json

# Download Guest List.csv from Facebook event page and copy it to a file named
# 'list.csv'. Remove the first line (column title) and the '"'s around each
# name (they cause trouble with MySQL)
filename = "list.csv"
data = open(filename, 'r')
guests = []

# Config Setup
config_file = open('config.json', 'r')
config = json.load(config_file)

for line in data:
   person = line.split(',')
   guests.append([person[0].strip(), person[1].strip()])

print("Number of guests {}\n".format(str(len(guests))))

db = MySQLdb.connect(config['db_host'], config['db_user'], config['db_password'],
 config['db_name'])
cursor = db.cursor()

for person, status in guests:
   print("Adding " + person + " status: " + status)
   cursor.execute("INSERT INTO {} (name, status)\
         VALUES (\"{}\", \"{}\")".format(db_table, person, status))

# Clean up
cursor.close()
db.commit()
db.close()
