Find Jobs
Hire Freelancers

convert php script to python

$30-250 USD

En curso
Publicado hace alrededor de 16 años

$30-250 USD

Pagado a la entrega
The maximum I will pay for this is $35. I have a php script that results in a comma delimited file. I want to convert it to python: The following code outputs a comma delimited file . The sql query that is used is "SELECT count( [login to view URL] ) AS amount , [login to view URL] , [login to view URL] FROM wordlocation , wordlist , urllist WHERE [login to view URL] = [login to view URL] AND [login to view URL] = [login to view URL] GROUP BY urlid , wordid"; I was wondering if you could write this for python so that it deposits a comma delimited file in a subfolder of the folder where this script is run called FREQUENCIES. (The folder does not exist so it should be created) Here is all the code in PHP (it also gives an html output but that is not necessary): <html> <body> <?php // database connection parameters define('DB_HOST', 'localhost'); define('DB_USER', ''); define('DB_PASS', ''); define('DB_DATABASE', '[login to view URL]'); define('DELIMITER', ','); // delimiter for CSV files // filename where results should be written, make sure you have write permissions to that file define('RESULTS_FILE', '[login to view URL]'); // specify output type, can be either HTML or CSV define('OUTPUT_TYPE', 'HTML'); // function returns amount of words for url function getAmount($matrix, $url, $word) { for ($i=0; $i<count($matrix); $i++){ if ($matrix[$i]['url'] == $url && $matrix[$i]['word'] == $word){ return $matrix[$i]['amount']; } } return 0; } // outputs HTML table function getHTMLOutput($matrix, $words, $urls) { $output = '<table border="1" cellpadding="4">'; $output .= '<tr>'; $output .= '<th> </th>'; foreach($words as $key => $word){ $output .= '<th>'.$word.'</th>'; } $output .= '</tr>'; foreach($urls as $key => $url){ $output .= '<tr>'; $output .= '<td>'.$url.'</td>'; foreach($words as $key2 => $word){ $output .= '<td>'.getAmount($matrix, $url, $word).'</td>'; } $output .= '<tr>'; } $output .= '</table>'; return $output; } // outputs CSV formated file function getCSVOutput($matrix, $words, $urls) { $csv = fopen(RESULTS_FILE, 'w'); $line = array_merge(array(' '), $words); fputcsv($csv, $line, DELIMITER); foreach($urls as $key => $url){ $line = array(); $line[0] = $url; foreach($words as $key2 => $word){ $line[] = getAmount($matrix, $url, $word); } fputcsv($csv, $line, DELIMITER); } fclose($csv); return '<a href="'.RESULTS_FILE.'">'.RESULTS_FILE.'</a>'; } $conn = mysql_connect(DB_HOST, DB_USER, DB_PASS); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db(DB_DATABASE)) { echo "Unable to select database: " . mysql_error(); exit; } $query = "SELECT count( [login to view URL] ) AS amount , [login to view URL] , [login to view URL] FROM wordlocation , wordlist , urllist WHERE [login to view URL] = [login to view URL] AND [login to view URL] = [login to view URL] GROUP BY urlid , wordid"; $result = mysql_query($query); if (!$result) { echo "Could not successfully run query ($query) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print, exiting"; exit; } $words = array(); $urls = array(); $matrix = array(); while ($row = mysql_fetch_assoc($result)) { $words[] = $row['word']; $urls[] = $row['url']; $matrix[] = $row; } mysql_free_result($result); // extract only unique words and urls $words = array_unique($words); $urls = array_unique($urls); if (OUTPUT_TYPE == 'CSV'){ // CSV OUTPUT echo getCSVOutput($matrix, $words, $urls); } else{ // HTML OUTPUT echo getHTMLOutput($matrix, $words, $urls); } ?> </body> </html>
ID del proyecto: 234080

Información sobre el proyecto

3 propuestas
Proyecto remoto
Activo hace 16 años

¿Buscas ganar dinero?

Beneficios de presentar ofertas en Freelancer

Fija tu plazo y presupuesto
Cobra por tu trabajo
Describe tu propuesta
Es gratis registrarse y presentar ofertas en los trabajos
Adjudicado a:
Avatar del usuario
hi,pls chk pm.
$35 USD en 1 día
5,0 (1 comentario)
1,1
1,1
3 freelancers están ofertando un promedio de $35 USD por este trabajo
Avatar del usuario
Dear, I can create the python program according to your needs. Regards.
$35 USD en 3 días
3,2 (4 comentarios)
2,4
2,4
Avatar del usuario
I can offer it
$35 USD en 1 día
0,0 (0 comentarios)
0,0
0,0

Sobre este cliente

Bandera de JAPAN
Beppu shi, Japan
4,9
53
Forma de pago verificada
Miembro desde ago 30, 2005

Verificación del cliente

¡Gracias! Te hemos enviado un enlace para reclamar tu crédito gratuito.
Algo salió mal al enviar tu correo electrónico. Por favor, intenta de nuevo.
Usuarios registrados Total de empleos publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Cargando visualización previa
Permiso concedido para Geolocalización.
Tu sesión de acceso ha expirado y has sido desconectado. Por favor, inica sesión nuevamente.