Created
August 8, 2013 19:43
-
-
Save Celeo/6188008 to your computer and use it in GitHub Desktop.
Another Python EVE API script. Here, we check for a file called api.txt where the user places a series of api keys, codes, and character names for checking. The code is launched with as many checks as needed, and then loops through all characters and all checks to determine who does not have the specified skills and the appropriate level.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reads from a file called api.txt in the same director as this script. That file should be setup in the manner of | |
keyID,vCode,Character Name | |
keyID,vCode,Character Name | |
keyID,vCode,Character Name | |
keyID,vCode,Character Name | |
for as many lines as you wish to be checked. | |
This script is then ran with the following parameters: | |
python checkpreqs.py FirstSkill:Level SecondSkill:Level ThirdSkill:Level ... | |
""" | |
print 'Initializing ...' | |
import evelink, datetime, sys, os, re | |
r = '' | |
g = '' | |
w = '' | |
try: | |
from colorama import init, Fore | |
r = Fore.RED | |
g = Fore.GREEN | |
w = Fore.WHITE | |
init(autoreset=True) | |
print w + 'Colorama modules loaded' | |
except ImportError: | |
print 'Colorama module not found - will not be able to use color in printouts' | |
class CharKey: | |
def __init__(self, keyID, vCode, characterName): | |
self.keyID = keyID | |
self.vCode = vCode | |
self.characterName = characterName | |
class SkillCheck: | |
def __init__(self, skillName, level): | |
self.skillName = skillName | |
self.level = level | |
skillChecks = [] | |
writeToFile = False | |
print w + 'Loading lanch parameters ...' | |
for arg in sys.argv: | |
if arg is not None and re.match('\w{1,30}:\d', arg): | |
data = arg.split(':') | |
skillChecks.append(SkillCheck(skillName=data[0], level=data[1])) | |
if arg == '-write': | |
writeToFile = True | |
if not skillChecks: | |
sys.exit(r + 'Error: No skill checks provided, or they were in the wrong form') | |
if writeToFile: | |
print g + 'Will write results to file checkprereqs_out.txt instead of flushing to console.' | |
writeFile = open('checkprereqs_out.txt', 'w') | |
charKeys = [] | |
print w + 'Checking for api.txt and loading from file ...' | |
try: | |
f = open('api.txt') | |
for line in f: | |
if re.match('\d{7},\w{64},[a_zA-Z0-9 ]', line): | |
data = line.split(',') | |
data[2] = data[2].replace('\n', '') | |
charKeys.append(CharKey(keyID=data[0], vCode=data[1], characterName=data[2])) | |
print g + 'Character ' + w + data[2] + g + ' will be checked' | |
else: | |
print r + 'Line ' + w + line + r + ' does not match the regex requirements' | |
f.close() | |
except IOError: | |
sys.exit(r + 'Cannot find api.txt') | |
print w + 'Connecting to the EVE API ...' | |
eve = evelink.eve.EVE() | |
defaultapi = evelink.api.API() | |
def getCharacterID(charname): | |
return eve.character_id_from_name(charname) | |
def getCharacterName(charid): | |
return eve.character_name_from_id(charid) | |
print w + 'Fetching skill tree ...' | |
tree = {} | |
skilltree = eve.skill_tree() | |
for group in skilltree.itervalues(): | |
for skill in group['skills'].itervalues(): | |
name = None | |
skillid = None | |
for a, b in skill.iteritems(): | |
if a == 'name': | |
name = b | |
elif a == 'id': | |
skillid = b | |
tree[name.replace(' ', '_')] = skillid | |
def getSkillName(skillID): | |
for a,b in tree.iteritems(): | |
if b == skillID: | |
return a | |
def getSkillID(skillName): | |
for a,b in tree.iteritems(): | |
if a == skillName: | |
return b | |
print w + 'Checking launch parameters ...' | |
for s in skillChecks: | |
if s.skillName in tree: | |
print g + 'Skill ' + w + s.skillName + g + ' will be checked at level ' + w + str(s.level) | |
else: | |
sys.exit(r + 'Skill name ' + w + s.skillName + r + ' not recognized!') | |
print w + 'Checking by character ...' | |
for key in charKeys: | |
print g + 'Checking ' + key.characterName + ' ...' | |
api = evelink.api.API(api_key=(key.keyID, key.vCode)) | |
charid = getCharacterID(key.characterName) | |
char = evelink.char.Char(api=api, char_id=charid) | |
charsheet = char.character_sheet() | |
for check in skillChecks: | |
for skill in charsheet['skills']: | |
if skill['id'] == getSkillID(check.skillName): | |
if int(skill['level']) < int(check.level): | |
if writeToFile: | |
writeFile.write(key.characterName + ' does not have the skill ' + check.skillName + ' at the right level. Looking for ' + str(check.level) + ', found ' + str(skill['level']) + '\n') | |
else: | |
print w + key.characterName + r + ' does not have the skill ' + w + check.skillName + r + ' at the right level. Looking for ' + w + str(check.level) + r + ', found ' + w + str(skill['level']) | |
writeFile.close() | |
print 'Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment