Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
The Hexenbracken
============

NOTE 5/20/2022:
First forked this from Funkaoshi way before I actually knew how to code and dealing with some legacy issues. Probably I'd need to start over to make whatever changes I'd want to make correctly, although it looks like the issues I was attempting to address have been addressed anyway.

NOTE 10/5/2018:
This version has been modified by Max Cantor and has been adapted for python3.
hex.py and hexmaps.py have been altered, and utfcsv.py is now obsolete.
Additionally, there were some mistakes or omissions in the original instructions.
Check out my blog!: https://weirdwonderfulworlds.blogspot.com/

This python script will take a set of hex descriptions from a Google Doc and
turn them into a simple web site. Several example websites exist: [The
Hexenbracken][1] and [The Kraal][2], [The Colossal Wastes of Zhaar][3],
[Synthexia][4]. The source files that generate them are in this repository,
under the `hexmaps` folder.

Usage: `python hexmaps.py <input csv file> > <output html file>`
Usage:
1. You need to create a jinja template. As long as you stick to the proper .csv
format, you should be able to just copy the base.html template from the templates
folder into a new template, the same name as the .csv file (and eventually the
html page itself):

cp templates/base.html templates/[NAME].html

2. Then you can run the following through in unix bash (I used git bash):

python -Xutf8 hex.py hexmaps/[NAME].csv title > [NAME].html

The -Xutf8 has to do with the fact that I used Windows, if you use linux or
probably also mac I don't think that part is necessary.

You can use the flag `-f text` to tell the generator to use a text template,
rather than an HTML one. The script currently assumes the HTML template used to
Expand Down
24 changes: 12 additions & 12 deletions hex.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import argparse
import csv
import os
import re
import string
import sys

import jinja2

import utfcsv
import hexmap as hm

parser = argparse.ArgumentParser()
Expand All @@ -24,17 +24,17 @@

# Read CSV dump of Google Docs hex map descriptions and create hexmap of
# the data.
with open(args.CSV, 'rb') as csvfile:
hexmap = hm.HexMap(utfcsv.unicode_csv_reader(csvfile))
with open(args.CSV, encoding="utf-8") as csvfile:
hexmap = hm.HexMap(csv.reader(csvfile, dialect=csv.excel))


if args.fmt == 'stats':
print 'Most referenced Hexes:'
print('Most referenced Hexes:')
for l, count in hexmap.reference_histogram[-10:]:
print "\t%s mentioned %d times" % (l, count)
print 'Themes found in hexes:'
print("\t%s mentioned %d times" % (l, count))
print('Themes found in hexes:')
for l, count in hexmap.themes_histogram:
print "\t%s mentioned %d times" % (l, count)
print("\t%s mentioned %d times" % (l, count))
exit(0)


Expand All @@ -45,7 +45,7 @@ def settlementlink(m):
# exists.
settlement = m.group(1).upper().strip()
if settlement in hexmap.settlements:
return u"<a href='#{hex}' class='city-link'>{settlement}</a>".format(
return "<a href='#{hex}' class='city-link'>{settlement}</a>".format(
settlement=settlement, hex=hexmap.settlements[settlement])
return settlement

Expand All @@ -64,9 +64,9 @@ def hex2link(text):
def getreferences(h):
# return references for this hex.
if h in hexmap.references:
return u', '.join("<a class='hex-link' href='#%s'>%s</a>" % (l, l)
return ', '.join("<a class='hex-link' href='#%s'>%s</a>" % (l, l)
for l in sorted(hexmap.references[h]))
return u''
return ''

def coordinates(location):
return int(location[:2]), int(location[2:])
Expand Down Expand Up @@ -125,10 +125,10 @@ def process(description):

context = {
'hexes': sorted(hexmap.hexes.items()),
'authors': u", ".join("%s (%s)" % (author, count)
'authors': ", ".join("%s (%s)" % (author, count)
for author, count in hexmap.author_histogram.most_common()),
'references': hexmap.references,
'title': args.Title
}

print template.render(**context).encode('utf-8')
print(template.render(**context))
9 changes: 4 additions & 5 deletions hexmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def make_histogram(d):
histogram = [(l, len(i)) for l, i in d.iteritems()]
histogram = [(l, len(i)) for l, i in d.items()]
histogram = sorted(histogram, key=operator.itemgetter(1))
return histogram

Expand All @@ -18,7 +18,7 @@ def __init__(self, location, settlement, author, description, url, themes):
self.settlement = settlement.upper().strip()
self.themes = [t.upper().strip() for t in themes.split(',')]
self.author = author
self.description = description or '-'.encode('utf-8')
self.description = description or '-'
self.url = url


Expand Down Expand Up @@ -51,13 +51,13 @@ def __init__(self, csvfile):

# Yank out all the authors
self.authors = [d.author
for l, details in self.hexes.iteritems() for d in details
for l, details in self.hexes.items() for d in details
if d.author]
self.author_histogram = collections.Counter(self.authors)

# Yank out all references
self.references = collections.defaultdict(set)
for l, details in self.hexes.iteritems():
for l, details in self.hexes.items():
for d in details:
for m in re.finditer(r"\[\[(\d\d\d\d)\]\]", d.description):
if l != m.group(1):
Expand All @@ -76,4 +76,3 @@ def reference_histogram(self):
@property
def themes_histogram(self):
return make_histogram(self.themes)

Loading