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" postFixList =["AA-A","BA-A","CL-Y","DL-Y","EG-Y","FG-Y","YE-A","ZE-A"] 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].*") listeH = [] listeG = [] #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") listeH.append(s['name']) elif patterng.match(s['name']): print(f"adding {s['name']} to list") listeG.append(s['name']) # also prepare dictionnary for after lh[p] = [] lmaxh[p] = 0 lg[p] = [] lmaxg[p] = 0 # lh = {"AA-A" : [], # "BA-A" : [], # "CL-Y" : [], # "DL-Y" : [], # "EG-Y" : [], # "FG-Y" : [], # "YE-A" : [], # "ZE-A" : []} # lmaxh = {"AA-A" : 0, # "BA-A" : 0, # "CL-Y" : 0, # "DL-Y" : 0, # "EG-Y" : 0, # "FG-Y" : 0, # "YE-A" : 0, # "ZE-A" : 0} # lg = {"AA-A" : [], # "BA-A" : [], # "CL-Y" : [], # "DL-Y" : [], # "EG-Y" : [], # "FG-Y" : [], # "YE-A" : [], # "ZE-A" : []} # lmaxg = {"AA-A" : 0, # "BA-A" : 0, # "CL-Y" : 0, # "DL-Y" : 0, # "EG-Y" : 0, # "FG-Y" : 0, # "YE-A" : 0, # "ZE-A" : 0} #h systems for s in listeH: # print(f"now dealing with {s}") for pre in postFixList: if pre in s: length = len(f"{name} {pre} h") cur = int(s[length:]) if cur > lmaxh[pre]: lmaxh[pre] = cur # print(s) lh[pre].append(s) for s in listeG: 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(lh) print("These are the H sized systems") print(lmaxh) # # print(lg) print("These are the G sized systems") print(lmaxg) #generate other systems for H lcandidates = {"AA-A" : [], "BA-A" : [], "CL-Y" : [], "DL-Y" : [], "EG-Y" : [], "FG-Y" : [], "YE-A" : [], "ZE-A" : []} 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) 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) with open(f"{name}-RESULTS.json",'w') as f: f.write(json.dumps(lcandidates, indent=4)) # length = len(f"{name} {pre} h") # print(pre) # if pre in s: # cur = int(s[length:]) # if cur > lmaxh[pre]: # lmaxh[pre] = cur # listeNonEDSM = [] # # #fill with all systems # # for i in ['A','B','C','D','E','F','G','Y','Z']: # print(i) # for j in ['A','C','E','L','G','G','Z']: # for k in ['A','Y','D','E']: # for l in range(0,600): # listeNonEDSM.append(f"{name} {i}{j}-{k} h{l}") # listeNonEDSM.append(f"{name} {i}{j}-{k} g{l}") # # # # listeNonEDSM = [x for x in listeNonEDSM if x not in listeCompat] # # # [print(s) for s in listeNonEDSM] # maxi = 0 # listeNbr = [] # for system in listeCompat: # inte = int(system[system.rfind('h')+1:]) # listeNbr.append(inte) # if inte > maxi: # maxi = inte # # potential = [] # # for i in range(0, maxi): # if i not in listeNbr: # potential.append(i) # # for i in range(0, len(potential)-10, 10): # print(potential[i:i+10]) # # #