In Progress

convert php script to python

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( [url removed, login to view] ) AS amount ,

[url removed, login to view] ,

[url removed, login to view]

FROM wordlocation , wordlist , urllist

WHERE [url removed, login to view] = [url removed, login to view]

AND [url removed, login to view] = [url removed, login to view]

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', '[url removed, login to view]');

define('DELIMITER', ','); // delimiter for CSV files

// filename where results should be written, make sure you have write permissions to that file

define('RESULTS_FILE', '[url removed, login to view]');

// 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( [url removed, login to view] ) AS amount ,

[url removed, login to view] ,

[url removed, login to view]

FROM wordlocation , wordlist , urllist

WHERE [url removed, login to view] = [url removed, login to view]

AND [url removed, login to view] = [url removed, login to view]

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>

Skills: SEO

See more: convert php python, convert php code python, php python converter, convert python php, php python convert, php convert python, script php convertir python, convert php script python, convert python script php, array_unique python, php python conversion, convert python php script, convertire php python, getcsvoutput, python array_unique, fputcsv python, python url convert, php script python, python php converter, html python converter, python php convert, find unique words python, can convert php script python, array_unique csv, Convert script

About the Employer:
( 53 reviews ) Beppu shi, Japan

Project ID: #234080

Awarded to:

ke888le

hi,pls chk pm.

$35 USD in 1 day
(1 Review)
1.1

3 freelancers are bidding on average $35 for this job

harmonyinfotech

Dear, I can create the python program according to your needs. Regards.

$35 USD in 3 days
(4 Reviews)
2.4
antony123

I can offer it

$35 USD in 1 day
(0 Reviews)
0.0