diff --git a/.gitignore b/.gitignore index fc612dd..997bc77 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ build.sh gamebuild/* !gamebuild/*.css !gamebuild/*.png +placebuild/* +!placebuild/.gitkeep +places.py variables.py \ No newline at end of file diff --git a/README.org b/README.org index ae773bb..529af8c 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/demo.org b/demo.org index 17172c5..a06c603 100644 --- a/demo.org +++ b/demo.org @@ -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> diff --git a/generateplaces.py b/generateplaces.py new file mode 100644 index 0000000..78a5804 --- /dev/null +++ b/generateplaces.py @@ -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("\n\n
\n