Browse Source

Add log parsing, restrict file format

marches
Josh Gordon 3 years ago
parent
commit
06bb5da8fa
  1. 4
      Worlds/Test1/logs/1.txt
  2. 41
      app/routes.py
  3. 4
      app/templates/marchLog.html

4
Worlds/Test1/logs/1.txt

@ -3,11 +3,11 @@ Date: 05-03-2019
X: 50
Y: 50
--------------
-----
Anthony Rinaldo
We burned the labs to the ground.
------------
-----
Josh Gordon
We did not burn the labs to the ground. The pit was 70 meters deep at the end.

41
app/routes.py

@ -100,24 +100,29 @@ def marchLog(world,logname):
#logname is title of adventure
#log type is (DateString,X,Y,[(Name,Text)])
worldDir = "../Worlds/"+world + "/"
lookup = json.load(open(worldDir + "log.json", 'r'))
logFile = open(worldDir+ "logs/" + lookup[logname],'r')
logData = logFile.read().split('\n')
X,Y = ""
date = ""
nom = ""
for i in logData:
tmp = i
tmp = tmp.split(":")
if tmp[0].lower() == "name":
nom = tmp[1]
else if tmp[0].lower() == "date":
date = tmp[1]
else if tmp[0].lower() == "x":
X = tmp[1]
else if tmp[0].lower() == "y":
Y = tmp[1]
return render_template("marchLog.html",worldname=world,log=("current time",40,50,[("Lorem","ipsum. this is some data. data data data."),("Anthony","Someone's gonna see this code and theyre gonna shoot me")]))
lookup = json.load(open(worldDir + "log.json", 'r'))
logFile = open(worldDir+ "logs/" + lookup[logname],'r')
logData = logFile.read().split('\n')
name = logData[0].split(":")[1]
date = logData[1].split(":")[1]
X = logData[2].split(":")[1]
Y = logData[3].split(":")[1]
logs = []
for i in range(4,len(logData)):
if len(logData[i]) == 0:
continue
if logData[i] == "-----":
char = logData[i+1]
text = ""
i += 1 #adjust offset in file. We are now at the player's name
s = logData[i] #s will be the next line of the player's entry
while len(s) > 0: #while there is more written text
s = logData[i+1] #grab line of text
text += "\n"+s
i += 1
logs.append((char,text))
return render_template("marchLog.html",worldname=world,log=(name,date,X,Y,logs))
def bucket_route(uri, dir, sing=None):
if sing is None:

4
app/templates/marchLog.html

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block content %}
{% set (sdate,x,y,ls) = log %}
<h2><a href="/marches/worlds/{{worldname}}">{{sdate}}</a></h2>
{% set (logname,sdate,x,y,ls) = log %}
<h2><a href="/marches/worlds/{{worldname}}">{{logname}}, {{sdate}}</a></h2>
{% for (char,text) in ls %}
<h3>{{char}}</h3>
<p>{{text}}</p>

Loading…
Cancel
Save