import requests as r import re import json #IMPORTANT BITS ###This is the name of the sector you want to search into (Do not use caps!) name = "Cleeque" ### don't touch any of this. Or do, I'm a comment, not a cop. postFixList =["AA-A","BA-A","CL-Y","DL-Y","EG-Y","FG-Y","YE-A","ZE-A"] ###Call to EDSM API, don't run this script too much in a short timeframe. def apiCall(systemName): systems = r.get("https://www.edsm.net/api-v1/systems", params={'systemName' : systemName}) return systems patternh = re.compile(".*[ABCDEFGYZ][ACELGGZ]-[AYDE] [h].*") patterng = re.compile(".*[ABCDEFGYZ][ACELGGZ]-[AYDE] [g].*") listH = [] listG = [] lh = {} lmaxh = {} lg = {} lmaxg = {} lcandidates = {} #fetch sector + postfix data from edsm for p in postFixList: for s in json.loads(apiCall(name +" "+p).content): if patternh.match(s['name']): #print(f"adding {s['name']} to list") listH.append(s['name']) elif patterng.match(s['name']): #print(f"adding {s['name']} to list") listG.append(s['name']) # also prepare dictionnary for later lh[p] = [] lmaxh[p] = 0 lg[p] = [] lmaxg[p] = 0 lcandidates[p] = [] #Sorting H systems into postfix dict entries for s in listH: for pre in postFixList: if pre in s: length = len(f"{name} {pre} h") ##TODO replace this bullshit cur = int(s[length:]) if cur > lmaxh[pre]: lmaxh[pre] = cur lh[pre].append(s) #Same with G systems for s in listG: for pre in postFixList: if pre in s: length = len(f"{name} {pre} g") cur = int(s[length:]) if cur > lmaxg[pre]: lmaxg[pre] = cur lg[pre].append(s) print("These are the H sized systems known to EDSM") print(lmaxh) print("These are the G sized systems known to EDSM") print(lmaxg) #generate all the systems for H and adds it to the candidate dict only if its not on EDSM for i in postFixList: maxi = lmaxh[i] for j in range(maxi): sys = f"{name} {i} h{j}" if sys not in lh[i]: lcandidates[i].append(sys) #same for G systems for i in postFixList: maxi = lmaxg[i] for j in range(maxi): sys = f"{name} {i} g{j}" if sys not in lg[i]: lcandidates[i].append(sys) #Finally writes the results to a JSON file. with open(f"{name}-RESULTS.json",'w') as f: f.write(json.dumps(lcandidates, indent=4))