LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2012, 05:32 AM   #1
mittfh
LQ Newbie
 
Registered: Oct 2009
Location: Kenilworth, Warks, UK
Distribution: Mageia 2 64-bit / Xfce
Posts: 12

Rep: Reputation: 0
Spreadsheet to Wikia template?


I have a spreadsheet containing a list of episode summaries for an ongoing (text) web serial, which I'd like to wikify (in the hope that a wiki format may be more 'accessible' for other readers to contribute than a spreadsheet!)

I've created a Wikia template, the parameters of which are below (abridged for the purposes of this post - it actually has eight fields):

Code:
{{events
|episode=
|date=
|title=
|events=
}}
Now, obviously I can export the spreadsheet as a csv, but then comes the problem of converting:

Code:
"a1","a2","a3","a4"
"b1","b2","b3","b4"
and so on

to:

Code:
{{events
|episode=a1
|date=a2
|title=a3
|events=a4
}}
{{events
|episode=b1
|date=b2
|title=b3
|events=b4
}}
and so on.

The basic algorithm would presumably be along the lines of taking each line in turn, extracting everything between the "," character sequence to an array, then appending it to a text file together with the rest of the wiki markup. I'd obviously test it on a small (say, 10 episode) extract before subjecting it to the full 1,200 (which I'd probably split over multiple pages of about 100 episodes each for convenience).

The text extraction is probably the most complicated aspect, together with writing the output to file (unless done in shell script with echos and >>s).

I know the basics of programming, but it's been about a decade since I did any (Java, for a Computer Science degree, unhelpfully using custom file IO classes built by the uni).

So what would be your recommendations for an appropriate language to use to write this code (e.g. shell script / perl / python / other), and could you share either the relevant operators or a useful language reference so I can swot up myself?
 
Old 06-24-2012, 11:24 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by mittfh View Post
So what would be your recommendations for an appropriate language to use to write this code
I'd use awk. CSV parsing is, as you surmised, pretty difficult/annoying to do in a robust manner, but I've shown one working approach here. That one is basically an awk skeleton which parses the CSV data (RFC 4180), each line into an awk record, and each field into an awk field. It should handle quoted commas et cetera correctly. You might wish to use RS = "(\r\n|\n\r|\r|\n)" to allow any newline convention, though.

After the skeleton part of that script (as "user rules"), you'd only need an output rule, something along the lines of
Code:
{    printf("{{events\n|episode=%s\n|date=%s|title=%s|events=%s}}\n", $1, $2, $3, $4) }
To save the output to a file, just redirect the output to a file.
 
Old 06-25-2012, 03:45 PM   #3
mittfh
LQ Newbie
 
Registered: Oct 2009
Location: Kenilworth, Warks, UK
Distribution: Mageia 2 64-bit / Xfce
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for that - I've bookmarked the two threads and will have a go later this week, when I'm feeling less tired
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Resume creator - export options : template vs non-template approach vharishankar Programming 1 12-07-2011 11:11 PM
system froze when I clicked Save for Calc spreadsheet, now the spreadsheet is gone Stringdude Linux - Newbie 2 11-24-2010 01:05 AM
I got switched from a word process doc. into spreadsheet form. now ALL is spreadsheet 293 manzanita Linux - Newbie 1 08-04-2010 01:14 PM
from django.template import Template, gives output firedancer Linux - Newbie 0 11-30-2007 02:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration