GetAFreelancer.com
 
Find projectsSearch
Sign Up | Log in | Top Rated Users | Browse projects | Post Project | RSS feeds | Articles
 

convert php script to python

   Click here to post similar project

convert php script to python is project number 234080 posted at GetAFreelancer.com. Click here to post your own project.

Status: Closed (Selected Service Provider)
Selected Providers: selected service provider ke888le
Budget: $30-250
Created: 03/06/2008 at 3:42 EST
Bidding Ends: 03/07/2008 at 3:42 EST
Project Creator: willie108 View PM Post PM
Buyer Rating: 10.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/10
(3 reviews)
Description: 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( wordlocation.wordid ) AS amount ,
wordlist.word ,
urllist.url
FROM wordlocation , wordlist , urllist
WHERE wordlist.rowid = wordlocation.wordid
AND urllist.rowid = wordlocation.urlid
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', 'test.db');

define('DELIMITER', ','); // delimiter for CSV files
// filename where results should be written, make sure you have write permissions to that file
define('RESULTS_FILE', 'results.csv');
// 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>&nbsp;</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( wordlocation.wordid ) AS amount ,
wordlist.word ,
urllist.url
FROM wordlocation , wordlist , urllist
WHERE wordlist.rowid = wordlocation.wordid
AND urllist.rowid = wordlocation.urlid
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>
Report violation
Job Type:
  • SEO
Database: Other
Operating system: (None)
Bid count: 3
Average bid: $ 35

 

Related project
 
Nonpublic project #312358 Featured Nonpublic
login to view
 

FREE Trial project for new buyers!

 

View Project Message Board     Post Message on Project Message Board
Messages Posted: 0

If you are the project creator or one of the bidders Log in as project creator or bidder for more options

Bid on This Project

Service Providers PMB Bid Delivery Within Time of Bid Provider Rating
ke888le
View PM Post PM
$ 35 1 day 03-06-2008 09:20 EST 10.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/10
(18 reviews)
hi,pls chk pm.
harmonyinfotech
View PM Post PM
$ 35 3 days 03-06-2008 06:08 EST 10.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/1010.00/10
(1 reviews)
Dear, I can create the python program according to your needs. Regards.
antony123
View PM Post PM
$ 35 1 day 03-06-2008 05:34 EST 9.00/109.00/109.00/109.00/109.00/109.00/109.00/109.00/109.00/109.00/10
(7 reviews)
I can offer it
Bid on This Project

 

[ Web Development ] [ Join GAF Free ] [ Web Forms ]

What is GetAFreelancer.com? ( Read about the company )

Deposit money and don't purchase until your project is completed. We provide a safe escrow environment and you don't release the money until project is completed. Bookmark our homepage to make sure you don't forget about our website next time you need to develop an IT project for yourself or your company. Outsource projects and save a lot of money. Getting affordable freelance work, freelance programming and custom web design done for your website has never been easier. Buy services with help from our secure escrow system. We have thousands of satisfied clients around the world.

If you never tried to contract work to another part of the world you have your chance today. Sign up free! A freelancer is an independent worker, not on salary, hired instead on a project basis. Companies of any size have used our web services. Web Development doesn't have to be expensive. Outsourcing will cut your expenses by more than 50%. Would you like to outsource your next project? Would you like to make money as a freelancer? Click Sign Up to start!

Find Webmaster Resources and Webmaster Forum. Take a look at Search Engine Submission.