\documentclass{weird}

\def\indent{\space\space\space\space}

\catcode`{=12
\catcode`}=12
\catcode`<=1
\catcode`>=2
\def\{<{>
\def\}<}>
\catcode`{=1
\catcode`}=2
\catcode`<=12
\catcode`>=12

% This actually works.  Who knew?
\def\ { }
\def\ldots#1{...#1}
\def\texttrademark#1{(tm)#1}

\makeatletter
\def\@setowner#1{}

\def\'#1{&#1acute;}
\def\^#1{&#1circ;}

\let\ne=\noexpand
\let\ea=\expandafter
\let\ue=\unexpanded

\def\iwo{\immediate\write\out}

% Use HTML formatting, not tex formatting
\def\xhtml#1{%
  \def\textbf##1{<b>##1</b>}%
  \def\par{<br/>}%
  \def\noindent{}%
  #1%
}
\def\spyinfo#1{}

% Handle groups that know weird names
\def\writefull{\iwo{"\fullplain"}}

\begin{document}

\newwrite\out
\immediate\openout\out=gametex_codes.py


\iwo{codes=\{}
\EVERY{Code}{%
  \typeout{\expandafter\string\ME}%
  \xhtml{\iwo{%
    \indent r"\expandafter\string\ME":\{'string':"\MYnumber",
                                        'effect':r"""\MYeffect""",
					'gifts':[}}
  \begingroup
  \@ownermappings{Green}{\MYgreens}
  \@elementmapping{Green}{\iwo{\indent\indent "\MYsimplename",}}
  \MYgreens
  \endgroup
  \begingroup
  \SURFACEMAP{Blue}{\iwo{\indent\indent "\MYsimplename",}}
  \MYblues
  \endgroup
  \begingroup
  \SURFACEMAP{Abil}{\iwo{\indent\indent "Ability: \MYsimplename",}}
  \MYabils
  \endgroup
  \begingroup
  \MAP{Abil}{\iwo{\indent\indent "Ability: \MYsimplename",}}
  \SURFACEMAP{Green}{\MYabils}
  \MYgreens
  \endgroup
  \iwo{],'drops':[}
  \begingroup
  \SURFACEMAP{White}{\iwo{\indent\indent "\MYsimplename",}}
  \MYwhites
  \endgroup
  \begingroup
  \SURFACEMAP{Item}{\iwo{\indent\indent "Item: \MYsimplename",}}
  \MYitems
  \endgroup
  \iwo{                                 ]
					\},}}
\iwo{\}}

\end{document}
