2017-07-07 Text Mapper Command Line

I recently posted some examples of how to Traveller Subsector Generatorfrom the command line. Here’s how to do the same thing for Text Mapper.

xmllint allows us to extract text from XML and HTML documents. On a Debian system, it’s part of libxml2-utils.

Generate a text file with a 20x20 alpine wilderness map:

perl text-mapper.pl get /alpine 2>/dev/null | xmllint --html --xpath '//textarea/text()' - > random-alpine-map.txt

You’ll note that at the very end it contains the seed value.

You can regenerate the same map using this seed:

perl text-mapper.pl get "/alpine?seed=1499413794" 2>/dev/null | xmllint --html --xpath '//textarea/text()' - > 1499413794.txt

You can also modify the width and breadth of the map:

perl text-mapper.pl get "/alpine?width=10&height=5" 2>/dev/null | xmllint --html --xpath '//textarea/text()' - > random-alpine-map.txt

Let’s define an alias to handle the encoding of the map for us:

alias encodeURIComponent='perl -pe '\''s/([^a-zA-Z0-9_.!~*()'\''\'\'''\''-])/sprintf("%%%02X",ord($1))/ge'\'

Make some changes to the text file generated above using a text editor and generate the updated map:

perl text-mapper.pl get --header 'Content-Type:application/x-www-form-urlencoded' --method POST --content map=$(cat 1499413794.txt|encodeURIComponent) /render 2>/dev/null > 1499413794.svg

You can use svgexport to generate a PNG image, if you want.

First, install it:

npm install svgexport -g

You need to tell it what quality to use when exporting. I use 100% for PNG files; I’d use less for JPG files.

svgexport 1499413794.svg 1499413794.png 100%

I guess I have all the tools to create a Twitter bot? ;)



Please make sure you contribute only your own work, or work licensed under the GNU Free Documentation License. See Info for text formatting rules. You can edit the comment page if you need to fix typos. You can subscribe to new comments by email without leaving a comment.

To save this page you must answer this question:

Please say HELLO.