Find Jobs
Hire Freelancers

convert php script to python

$30-250 USD

In Progress
Posted about 16 years ago

$30-250 USD

Paid on delivery
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>
Project ID: 234080

About the project

3 proposals
Remote project
Active 16 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
hi,pls chk pm.
$35 USD in 1 day
5.0 (1 review)
1.1
1.1
3 freelancers are bidding on average $35 USD for this job
User Avatar
Dear, I can create the python program according to your needs. Regards.
$35 USD in 3 days
3.2 (4 reviews)
2.4
2.4
User Avatar
I can offer it
$35 USD in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of JAPAN
Beppu shi, Japan
4.9
53
Payment method verified
Member since Aug 30, 2005

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.