Compare commits
3 Commits
eab9d37f95
...
1717d25ddb
| Author | SHA1 | Date | |
|---|---|---|---|
| 1717d25ddb | |||
| 400cfeb61f | |||
| a628653d02 |
157
edsmAround.py
157
edsmAround.py
|
|
@ -1,15 +1,25 @@
|
||||||
import requests as r
|
import requests as r
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime as dt
|
||||||
|
from math import floor
|
||||||
|
|
||||||
#IMPORTANT BITS
|
#IMPORTANT BITS
|
||||||
|
|
||||||
###This is the name of the sector you want to search into (Do not use caps!)
|
###This is the name of the sector you want to search into (Do not use caps!)
|
||||||
name = "Cleeque"
|
sectorName = "Phleedgaa"
|
||||||
|
|
||||||
|
|
||||||
|
### "weights" to query, beware of big results when searching for lighter systems in more dense area
|
||||||
|
weightsToQuery = ["a","b","c","d","e"]
|
||||||
|
|
||||||
|
|
||||||
|
### postFix List, modify as needed
|
||||||
|
#postFixList =["AA-A","BA-A","CL-Y","DL-Y","EG-Y","FG-Y","YE-A","ZE-A"]
|
||||||
|
postFixList =["UJ-Q"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 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.
|
###Call to EDSM API, don't run this script too much in a short timeframe.
|
||||||
def apiCall(systemName):
|
def apiCall(systemName):
|
||||||
|
|
@ -17,89 +27,94 @@ def apiCall(systemName):
|
||||||
return systems
|
return systems
|
||||||
|
|
||||||
|
|
||||||
|
# takes a sector name, a postfix and a weight, returns list of known systems in EDSM matching that
|
||||||
|
def fetchEdsmSystems(sectorName, postFix, weight):
|
||||||
|
hasMultipleHyphens = False
|
||||||
|
systemList = []
|
||||||
|
pattern = re.compile(f".*{postFix} {weight}.*")
|
||||||
|
for system in json.loads(apiCall(sectorName +" "+postFix).content):
|
||||||
|
if pattern.match(system['name']):
|
||||||
|
systemList.append(system['name'])
|
||||||
|
hasMultipleHyphens = system['name'].count("-") > 1 # if at least one of those has multiple hyphens, we consider all of them do
|
||||||
|
return systemList, hasMultipleHyphens
|
||||||
|
|
||||||
patternh = re.compile(".*[ABCDEFGYZ][ACELGGZ]-[AYDE] [h].*")
|
#given a list of systems (assumed to be all the same weight and postfix) returns the maximum value of the integer value in the system name for that list
|
||||||
patterng = re.compile(".*[ABCDEFGYZ][ACELGGZ]-[AYDE] [g].*")
|
def maxSystemValue(systemList):
|
||||||
|
currentMax = 0
|
||||||
|
patternWithoutHyphen = re.compile(f".*[A-Z][A-Z]-[A-Z] [A-Za-z]([0-9]+)")
|
||||||
|
patternWithHyphen = re.compile(f".*[A-Z][A-Z]-[A-Z] [A-Za-z][0-9]*-([0-9]+)")
|
||||||
|
for system in systemList:
|
||||||
|
val = 0
|
||||||
|
|
||||||
|
if system.count("-") > 1:
|
||||||
|
match = patternWithHyphen.match(system)
|
||||||
|
else:
|
||||||
|
match = patternWithoutHyphen.match(system)
|
||||||
|
|
||||||
|
val = int(match.group(1))
|
||||||
|
if val > currentMax:
|
||||||
|
currentMax = val
|
||||||
|
return currentMax
|
||||||
|
|
||||||
|
|
||||||
listH = []
|
#dict of dict of systems keyed by postfix, keyed by weight ( dict["AA-A"]["g"] gives back all the AA-A GXXX systems)
|
||||||
listG = []
|
sysWeightDict = {}
|
||||||
lh = {}
|
|
||||||
lmaxh = {}
|
#dict of dict of systems maximum value by postfix, keyed by weight ( dict["AA-A"]["g"] gives back the maximum recorded value for X where X is the integer in a system name : AA-A GX)
|
||||||
lg = {}
|
sysMaxDict = {}
|
||||||
lmaxg = {}
|
|
||||||
lcandidates = {}
|
postFixWithMultipleHyphens = {} # deals with system names like "Sector AA-A e5-8"
|
||||||
|
|
||||||
|
#dict of dict of all the systems in a sector keyed by postfix, keyed by weight, used later for substracting EDSM values from ALL systems
|
||||||
|
sysCandidates = {}
|
||||||
|
|
||||||
|
|
||||||
#fetch sector + postfix data from edsm
|
base = ""
|
||||||
for p in postFixList:
|
reference = ""
|
||||||
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
|
#for each weight class, we initialize our dicts with our postfix list
|
||||||
|
for weight in weightsToQuery:
|
||||||
|
sysWeightDict[weight] = {}
|
||||||
|
sysMaxDict[weight] = {}
|
||||||
|
sysCandidates[weight] = {}
|
||||||
|
postFixWithMultipleHyphens[weight] = {}
|
||||||
|
|
||||||
lh[p] = []
|
#then we populate our dicts with the provided postfix
|
||||||
lmaxh[p] = 0
|
|
||||||
lg[p] = []
|
for postfix in postFixList:
|
||||||
lmaxg[p] = 0
|
sysWeightDict[weight][postfix], postFixWithMultipleHyphens[weight][postfix] = fetchEdsmSystems(sectorName, postfix, weight) # this is reversed from IG "AA-A G"
|
||||||
lcandidates[p] = []
|
sysMaxDict[weight][postfix] = maxSystemValue(sysWeightDict[weight][postfix])
|
||||||
|
|
||||||
|
#now we generate the inverse of the known system list
|
||||||
|
|
||||||
|
# for all systems indexes to the max known index
|
||||||
|
sysCandidates[weight][postfix] = []
|
||||||
|
|
||||||
|
if len(sysWeightDict[weight][postfix]) > 0:
|
||||||
|
|
||||||
|
if postFixWithMultipleHyphens[weight][postfix]: #if we have multiple hyphens we take the first system to see what's in front of the hyphen
|
||||||
|
reference = sysWeightDict[weight][postfix][0]
|
||||||
|
base = reference[:reference.rfind("-")+1]
|
||||||
|
print(f"Warning, sector {sectorName} {postfix} has multiple hyphens, predictions may be wrong!")
|
||||||
|
else:
|
||||||
|
base =f"{sectorName} {postfix} {weight}"
|
||||||
|
|
||||||
|
for i in range(sysMaxDict[weight][postfix]):
|
||||||
|
candidate = f"{base}{i}"
|
||||||
|
if candidate not in sysWeightDict[weight][postfix]:
|
||||||
|
sysCandidates[weight][postfix].append(candidate)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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
|
print("These are the systems known to EDSM")
|
||||||
for s in listG:
|
print(sysMaxDict)
|
||||||
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.
|
#Finally writes the results to a JSON file.
|
||||||
with open(f"{name}-RESULTS.json",'w') as f:
|
with open(f"{floor(dt.now().timestamp())}-{sectorName}-RESULTS-v2.json",'w') as f:
|
||||||
f.write(json.dumps(lcandidates, indent=4))
|
f.write(json.dumps(sysCandidates, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user