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