def process(arg, csv_file):
    '''
    >>> process('http://live.feedjit.com/live/XXXXXXXXXXXXXXXXXX/0/', 'test.csv')
    Traceback (most recent call last):
        ...
    ValueError: Data Download Failed!
    '''
    plain_data = extracts_data(arg)
    plain_text = latin2text(plain_data)
    json_data = json.loads(plain_text)
    first_row = None
    csv_exists = False
    if os.path.exists(csv_file):
        f_in = open(csv_file, "rb")
        Reader = csv.reader(f_in, dialect=csv.excel)
        encabezado = Reader.next()
        first_row = Reader.next()
        csv_exists = True 
    f_out = open(csv_file+'~', 'wb')
    Writer = csv.writer(f_out, dialect=csv.excel)
    Writer.writerow(['URL', 'CC', 'COUNTRY', 'CITY', 'OS', 'BROWSER', 'DATE TIME', 'IP'])
    for row in rows_data(json_data):
        if row != first_row:
            Writer.writerow(row)
        else:
            Writer.writerow(first_row)
            for row_old in Reader:
                Writer.writerow(row_old)
            break
    f_out.close()
    if csv_exists:
        f_in.close()
        os.remove(csv_file)
    os.rename(csv_file+'~', csv_file)

    >>> process('http://live.feedjit.com/live/XXXXXXXXXXXXXXXXXX/0/', 'test.csv')
    Traceback (most recent call last):
        ...
    ValueError: Data Download Failed!
    
recipes/Python/577683_Extract_data_from_feedjit/recipe-577683.py