UseModElixir - wendysmoak/wiki GitHub Wiki

How to read and parse the .db files from UseMod?

{:ok, contents} = File.read("IPod.db")

http://www.usemod.com/cgi-bin/wiki.pl?UseModWiki/DeveloperQuestions

It is mostly delimited by superscript 3

defmodule UseMod do
  def convert(filename) do
    {:ok, contents} = File.read(filename <> ".db") 
    stuff = String.split(contents,"\xb33")
    text = Enum.at(stuff, 3)
    text = String.replace( text, "<pre>", "```" )
    text = String.replace( text, "</pre>", "```" )
    text = String.replace( text, "<nowiki>", "" )
    text = String.replace( text, "</nowiki>", "" )
    text = String.replace( text, "<toc>", "" )
    {:ok, file} = File.open(filename <> ".md", [:write])
    IO.write(file, text )
    File.close(file)
    File.rm(filename <> ".db")
  end

  def convert do
    files = Path.wildcard("*.db") 
    for full_filename <- files do
      filename = full_filename |> String.split(".") |> Enum.at(0) 
      convert(filename)
      System.cmd("git", ["add", filename <> ".md"]) 
    end
  end
end

Usage

iex and paste the code into the console

UseMod.convert("TheFileName")

Convert all .db files in the directory UseMod.convert

Errors

A handful of files couldn't be written:

> UseMod.convert
** (ErlangError) Erlang error: :no_translation
    (stdlib) :io.put_chars(#PID<0.327.0>, :unicode, <<61, 32, 69, 98, 97, 121, 32, 61, 13, 10, 13, 10, 45, 45, 45, 45, 45, 13, 10, 13, 10, 87, 104, 97, 116, 32, 112, 97, 121, 109, 101, 110, 116, 32, 109, 101, 116, 104, 111, 100, 115, 32, 97, 114, 101, 32, 97, 118, 97, 105, ...>>)
    iex:12: UseMod.convert/1
    iex:21: anonymous fn/2 in UseMod.convert/0
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    iex:19: UseMod.convert/0

I didn't figure out why, I just edited the file in Usemod and pasted the contents into the text editor to add to the Github wiki.

References

⚠️ **GitHub.com Fallback** ⚠️