Add place tracker

master
trémeur 6 months ago
parent fc286a07b5
commit 91c43c5671

3
.gitignore vendored

@ -3,4 +3,7 @@ build.sh
gamebuild/*
!gamebuild/*.css
!gamebuild/*.png
placebuild/*
!placebuild/.gitkeep
places.py
variables.py

@ -26,7 +26,16 @@ In =variables.py=, edit:
- =consoles=: add or remove consoles following the format provided (=.png= images must be added to the build directory with a filename corresponding with the value of ="img"= for each console)
** Testing
- Run =python3 generategames.py local= to build in =gamebuild=.
* First run
* Tracking places visited using Leaflet
** Setup
Upload a CSS file to the server if necessary. Most CSS is set by Leaflet.
*** Setting the variables
In =variables.py=, edit:
- =trackplaces=: set to =True=
- =placeserverpath=: path to directory on the server where files will be uploaded, including trailing slash
- =placestartyear=: year from which to begin tracking (an integer)
- =placecss=: location of the CSS file, relative to the site root
* First run (or if adding any new trackers)
- Run =python3 init.py= and then =chmod +x build.sh=.
- Create directories on the server corresponding to any =*serverpath= variables you have set.
* Building

@ -12,3 +12,7 @@ Notes about the games can be stored under each heading.
*** demo game 3 (pc)
** completed
*** demo game 4 (nintendo ds)
* places
** visited
*** demo place 1
*** demo place 2 <2024-02-17 Sat>--<2024-02-18 Sun>

@ -0,0 +1,132 @@
import orgparse,os,re,sys,variables
from datetime import datetime
import sys,variables
try:
if sys.argv[1] == "local":
local = True
else:
local = False
except:
local = False
if variables.trackgames == True:
thisyear = datetime.now().strftime("%Y")
year = variables.placestartyear
concernedfiles = []
while year < int(thisyear) + 1:
month = 0
while month < 13:
if month < 10:
strmonth = "0" + str(month)
else:
strmonth = str(month)
recdir = str(year) + "/" + strmonth + "/"
fullpath = variables.orgpath + recdir
if os.path.exists(fullpath):
for file in sorted(os.listdir(fullpath)):
filename = fullpath + str(file)
if filename.endswith(".org"):
concernedfiles.append(filename)
month = month + 1
year = year + 1
places = []
placenames = []
for file in concernedfiles:
filedate = file[-14:-4]
dateobj = datetime.strptime(filedate,"%Y-%m-%d")
parsefile = orgparse.load(file)
try:
for node in parsefile.children:
if node.heading == "places":
for action in node.children:
if action.heading == "visited":
for place in action.children:
placename = re.sub(" <.*>","",re.sub("<.*> ","",place.heading))
if placename not in placenames:
status = "new"
placenames.append(placename)
else:
status = "existing"
if "<" in place.heading:
dates = re.sub(" [A-Z][a-z][a-z]","",re.sub("--"," to ",re.sub(">","",re.sub("<","",(re.findall("\<.*\>",place.heading)[0])))))
else:
dates = filedate
if status == "new":
thedict = {"name":placename,"dates":[dates]}
places.append(thedict)
else:
twodict = {"name":placename,"dates":[dates]}
for origplace in places:
if twodict["name"] == origplace["name"]:
origplace["dates"].extend(twodict["dates"])
except:
pass
for place in places:
place["dates"] = list(dict.fromkeys(place["dates"]))
theplaces = sorted(places,key=lambda d: d["name"])
if os.path.isfile("places.py"):
import places
newplaces = []
for place in theplaces:
for location in places.places:
if place["name"] == location["name"]:
break
else:
newplaces.append(place["name"])
if len(newplaces) > 0:
with open("places.py","rb+") as editfile:
editfile.seek(-2, os.SEEK_END)
editfile.truncate()
appendfile = open("places.py","a")
for place in newplaces:
appendfile.write(",\n{\"name\":\"" + place + "\",\"lat\":0,\"long\":0}")
appendfile.write("]")
appendfile.close()
print("Add latitudes and longitudes in places.py before running again")
else:
alllats = []
alllongs = []
import places
for place in places.places:
if place["lat"] != 0:
alllats.append(place["lat"])
if place["long"] != 0:
alllongs.append(place["long"])
avglat = (max(alllats) + min(alllats))/2
avglong = (max(alllongs) + min(alllongs))/2
writefile = open("placebuild/index.html","w")
writefile.write("<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <base target=\"_top\">\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> \n <title>Map</title>\n <link rel=\"stylesheet\" href=\"")
if local:
writefile.write(variables.domain)
writefile.write(variables.placecss + "\"/>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/leaflet@1.9.4/dist/leaflet.css\" integrity=\"sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=\" crossorigin=\"\"/>\n <script src=\"https://unpkg.com/leaflet@1.9.4/dist/leaflet.js\" integrity=\"sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=\" crossorigin=\"\"></script>\n <style>\n #map {\n width: 90vw;\n height: 90vh;\n margin: auto;\n }\n </style>\n </head>\n <body>\n <div id=\"map\" style=\"width: 90vw; height: 90vh;\"></div>\n <script>\n const map = L.map('map').fitBounds([[" + str(min(alllats)) + ", " + str(min(alllongs)) + "],[" + str(max(alllats)) + ", " + str(max(alllongs)) + "]]);\n const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {\n attribution: '&copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>'\n }).addTo(map);\n")
for place in theplaces:
for location in places.places:
if location["name"] == place["name"]:
thelat = location["lat"]
thelong = location["long"]
saniname = re.sub(" ","",(re.sub("","",(re.sub("-","",place["name"])))))
writefile.write(" const " + saniname + " = L.marker([" + str(thelat) + ", " + str(thelong) + "]).addTo(map).bindTooltip('<h2>" + place["name"] + "</h2><ul>")
for date in place["dates"]:
writefile.write("<li><code>" + date + "</code></li>")
writefile.write("</ul>');\n")
writefile.write(" </script>\n </body>\n</html>")
else:
writefile = open("places.py","w")
writefile.write("places = [")
for place in theplaces:
writefile.write("{\"name\":\"" + place["name"] + "\",\"lat\":0,\"long\":0}")
if place != theplaces[-1]:
writefile.write(",\n")
writefile.write("]")
writefile.close()
print("Add latitudes and longitudes in places.py before running again")

@ -5,6 +5,9 @@ script = open("build.sh", "w")
script.write("#!/usr/bin/env bash\n")
if variables.trackgames == True:
script.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.gameserverpath + " -P")
script.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.gameserverpath + " -P\n")
if variables.trackplaces == True:
script.write("python3 generateplaces.py\nrclone copy placebuild " + variables.rclonesiteroot + variables.placeserverpath + " -P\n")
script.close()

@ -42,3 +42,7 @@ Places
trackplaces = False
placeserverpath = ""
placestartyear = 0
placecss = ""

Loading…
Cancel
Save