Go Back   Hardware Canucks > SOFTWARE > O/S's, Drivers & General Software

    
Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old September 14, 2011, 07:44 PM
Keywork's Avatar
Allstar
 
Join Date: Jun 2009
Location: Niagara
Posts: 604

My System Specs

Default

Alright! I'm just about done. One quick question though! For the links. If there is more than one, you want them all in one field correct?

Shoot me a PM with your email so I can send it to you or I can copy and paste it here? Let me know!

Also, it's a perl script so you'll have to either install it on your windows box OR run it natively on any Linux distro.
Reply With Quote
  #12 (permalink)  
Old September 14, 2011, 07:54 PM
SugarJ's Avatar
Moderator
F@H
 
Join Date: Jan 2008
Location: Langley, BC
Posts: 6,091

My System Specs

Default

I'm pretty sure you can attach a zip to a PM, but I'm sure a few folks would like to see what you have done. Hint. Hint.
Reply With Quote
  #13 (permalink)  
Old September 14, 2011, 08:40 PM
Keywork's Avatar
Allstar
 
Join Date: Jun 2009
Location: Niagara
Posts: 604

My System Specs

Default

Code:
#! /usr/bin/perl -w

##########
#
# KeyworK
#
# Script for DT dtscript.pl
#
##########

use strict;
use warnings;

my $file = shift;
open (INPUT, "<$file");

## FORMAT
## Author,Content,Date,Retweets,Links,Link#

# Input
# epaulnet: Nanaimo Daily News: #Qaddafi backed efforts against al-#Qaeda: DND reports‎ http://t.co/iTVFkqh #Libya 
# 04/23/2011 retweet

# Output
# epaulnet,Nanaimo Daily News: #Qaddafi backed efforts against al-#Qaeda: DND reports? http://t.co/iTVFkqh #Libya ,04/23/2011,0,http://t.co/iTVFkqh,1

my ($author, $content, $date, $retweets, @links, $length);
open (OUTPUT , ">output");
print OUTPUT "Author,Content,Date,Retweets,Links,Link# \n";
while (<INPUT>){
    chomp;
    if (/.*:.*/){ #Parses the main line
        #print "$_ \n";
        $_ =~ m/(.*?): (.*)/;
        ($author,$content) = ($1,$2);
        my @lines = split / /,$content;
        @links = grep (/http/,@lines);
        $length = scalar(@links);
    } elsif (/\d\d\/\d\d\/\d\d\d\d .*/){ #Parses the secondary line
        #print "$_ \n";
        my @line = split / /,$_;
        if ($line[1] eq "retweet"){ $line[1] = 0 }
        ($date, $retweets) = @line;
        print OUTPUT "$author,$content,$date,$retweets,@links,$length \n";
    } 
}
I need to go to bed, but I believe there is a bug if there exists a quotation mark in the content field, but I may be wrong. If you need any help running it, let me know!

Note: It takes the input file as an argument. ie: dtscript.pl input.txt
Reply With Quote
  #14 (permalink)  
Old September 15, 2011, 04:37 AM
Arinoth's Avatar
Moderator
F@H
 
Join Date: May 2009
Location: Halifax
Posts: 8,592

My System Specs

Default

Looks good, I'd of done it a slightly different way, but that may been due to the difference in programming language then actual algorithm
Reply With Quote
  #15 (permalink)  
Old September 15, 2011, 05:40 AM
"Quote This..."
F@H
 
Join Date: Nov 2007
Location: Hell
Posts: 3,833
Default

I'd run a search and replace to change any existing comma's to semi-colons first. Even if they did not cause a bug in your conversion routine, they will mess up the csv file.
Reply With Quote
  #16 (permalink)  
Old September 15, 2011, 06:21 AM
Keywork's Avatar
Allstar
 
Join Date: Jun 2009
Location: Niagara
Posts: 604

My System Specs

Default

Quote:
Originally Posted by Squeetard View Post
I'd run a search and replace to change any existing comma's to semi-colons first. Even if they did not cause a bug in your conversion routine, they will mess up the csv file.
Yup, I need to add a line in there to replace all commas and quotation marks with semi-colons or something. I'll try to make the adjustment quickly after i'm out of class. It's only one or two lines...

Note: I forgot to mention that last night when testing it quickly, I added some random quotes to the input file and ran the script. When I opened it in LibreOffice, it the CSV was broken, but when opened in Office, it was fine...
Reply With Quote
  #17 (permalink)  
Old September 15, 2011, 08:45 AM
Dead Things's Avatar
Hall Of Fame
F@H
 
Join Date: Oct 2008
Location: Centre of the Universe
Posts: 1,572

My System Specs

Default

Thanks Keywork, I played with it some this morning. It's perfect! Thanks so much - exactly what I needed. Simply amazing. I changed all the commas to semicolons and all the quotation marks to asterisks in the source document, and the csv file imported into SPSS perfectly. If I can return the favour in any way, please let me know. Don't suppose you'd be interested in a free 8800GTS?
__________________
Follow my folding, mining & benching shenanigans @dt_oc!

Think you can overclock? Then show us what you got!
Join the Hardware Canucks Overclocking team today!
Reply With Quote
  #18 (permalink)  
Old September 15, 2011, 08:57 AM
Keywork's Avatar
Allstar
 
Join Date: Jun 2009
Location: Niagara
Posts: 604

My System Specs

Default

Funny you mention an 8800GTS because the one I had in my secondary folding rig crapped out about a month ago haha. If it's working and it can fold, i've got a home for it! I would even cover shipping!
Reply With Quote
  #19 (permalink)  
Old September 15, 2011, 09:19 AM
Dead Things's Avatar
Hall Of Fame
F@H
 
Join Date: Oct 2008
Location: Centre of the Universe
Posts: 1,572

My System Specs

Default

PM me your address and I'll ship it out early next week. Thanks again!
__________________
Follow my folding, mining & benching shenanigans @dt_oc!

Think you can overclock? Then show us what you got!
Join the Hardware Canucks Overclocking team today!
Reply With Quote
Reply


Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some expertise here =P feerof Water Cooling 6 April 7, 2010 08:17 AM
Building a Intel i7/X58 System.. need your expertise. exxoid New Builds 18 May 16, 2009 10:55 PM
Programming Phobia O/S's, Drivers & General Software 9 November 16, 2008 03:54 PM
programming how to's? klaiboi Guides & How-to's 7 June 22, 2008 07:23 PM
Need your expertise! More power? misterlarry Video Cards 10 April 3, 2008 08:25 PM