#!/usr/bin/env python
# -*- coding: utf-8 -*-

from urllib2 import Request, urlopen, HTTPError, URLError
from csv_converter import CsvConverter
from stock_updater import StockUpdater
import sqlite3
import psycopg2
import mysql.connector
import os
import json

import database_helper

with open("config.json") as f:    
    config = json.load(f)

request = Request(config["source"]["url"])

try:
    response = urlopen(request)
except HTTPError as e:
    print "The server returned error {}".format(e.code)
    exit
except URLError as e:
    print "Failed to reach server: {}".format(e.reason)
    exit

converter = CsvConverter("")
converter.setSourceColumns(
    config["source"]["product_code_column"],
    config["source"]["quantity_column"])
converter.read_csv(response)

if config["database_connection"]["type"] == "sqlite3":
    conn = sqlite3.connect(config["database_connection"]["url"])
elif config["database_connection"]["type"] == "psql":
    conn = psycopg2.connect(
        "dbname='{}' user='{}' host='{}' password='{}".format(
            config["database_connection"]["database"],
            config["database_connection"]["username"],
            config["database_connection"]["host"],
            config["database_connection"]["password"]))
elif config["database_connection"]["type"] == "mysql":
    conn = mysql.connector.connect(
        user=config["database_connection"]["username"],
        password=config["password"]["password"],
        host=config["database_connection"]["host"],
        database=config["database_connection"]["database"])
else:
    raise "Please, define database"

if config["testing"]:
    database_helper.initialize(conn)
    database_helper.add_test_products(conn)

updater = StockUpdater(conn)
updater.set_perform_check_product(config["database_connection"]["check_products"])
updater.set_destination_colums(
    config["database_connection"]["product_code_column"],
    config["database_connection"]["quantity_column"])
updater.set_table(config["database_connection"]["products_table"])
updater.set_items(converter.rows)
updater.update()
@@ -195,24 +195,8 @@
 te3%0A
-import psycopg2%0A
 impo
@@ -877,371 +877,8 @@
 %22%5D)%0A
-elif config%5B%22database_connection%22%5D%5B%22type%22%5D == %22psql%22:%0A    conn = psycopg2.connect(%0A        %22dbname='%7B%7D' user='%7B%7D' host='%7B%7D' password='%7B%7D%22.format(%0A            config%5B%22database_connection%22%5D%5B%22database%22%5D,%0A            config%5B%22database_connection%22%5D%5B%22username%22%5D,%0A            config%5B%22database_connection%22%5D%5B%22host%22%5D,%0A            config%5B%22database_connection%22%5D%5B%22password%22%5D))%0A
 elif

Remove support for psql