开发者

Script for Generating Wordpress HTML codes from a csv file

I'm trying to make my life easier by making a script that generates HTML code for wordpress from a csv file. Here's the code I wrote:

    require 'csv'

File.open("output.txt", 'w') do |output_file|
  CSV.readlines("source.csv").each do |title, image, thumb, mp, gp|
    output_file.puts "<a href="#{image}"><img style="background-i开发者_高级运维mage: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="#{title}" src="#{thumb}" border="0" alt="#{title}" width="244" height="166" /></a>

<a href="#{mp}" target="_blank">Download HQ</a>

<a href="#{gp}" target="_blank">Download LQ</a>"
  end
end

I apologize but I'm not that good with coding. This code doesn't work and generated a lot of syntax errors lol.


We might need more information on how you are running this, but one error I see is with your string handling - you need to escape quotes:

puts "This "doesn't" work"

puts "This \"does\" work"

You can avoid this by using a different quote operator:

puts %|Now we can "use quotes" all we want|

Or with a heredoc:

puts <<EOF
Lots of "quoted text"
...
blah blah
EOF
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜