def readd_usb(serialArg, M, m): lxd = lxdClient() containers = lxd.containers.all() #zero extend major and minor numbers major = M.zfill(3) minor = m.zfill(3) #create the database if needed and open it if os.path.exists(jsonFile): fpgas = json.load(open(jsonFile)) else: write_json.write_json() fpgas = json.load(open(jsonFile)) for container in containers: fpgaSerialKey = "" try: fpgaSerialKey = container.config["user.fpga-serial"] except KeyError: continue #no FPGAs in this container for fpgaSerial in fpgaSerialKey.split(' '): if (serialArg == fpgaSerial): #this container has this FPGA update_path(container, serialArg, fpgas, major, minor)
def book_add(): #check if an author has been added author_check() #open books.json with open(filename) as json_file: data = json.load(json_file) temp = data['books'] #define the data that will be appended book_title = input("\nPlease enter the title of the book: \n") book_published = enter_date(filename) book_author = choose_author() book_publisher = input("\nPlease enter the publisher of the book: \n") book_isbn13 = input("\nPlease enter the ISBN of the book: \n") book_genre = choose_genre() book_pages = int( input("\nPlease enter the amount of pages of the book: \n")) y = { "title": book_title, "published": book_published, "authors": book_author, "publisher": book_publisher, "isbn-13": book_isbn13, "genre": book_genre, "pages": book_pages } #appending data to books.json temp.append(y) write_json(data, filename) print("\nBook added.")
def parse_quests(): page = open('./cache/quests/Raids.html', "r", encoding='utf-8').read() soup = BeautifulSoup(page, 'html.parser') raids = get_raids_from_page(soup) out = {} out['raids'] = raids write_json(out, 'quests')
def convert_imgs_to_b4s(dir_path): """ """ b64_strs = {} for file_name in os.listdir(dir_path): with open(dir_path + '\\' + file_name, 'rb') as img_file: b64_strs[file_name] = str( base64.b64encode(img_file.read()).decode('ascii')) b64_strs[file_name] = resolve_metatag( file_name) + b64_strs[file_name] n = len(os.listdir('./theme_dicts')) write_json(b64_strs, './theme_dicts/{}.json'.format(n + 1)) return b64_strs
def parse_item_pages(): sets = read_json('sets') cachePath = "./cache/items/" items = [] for file in os.listdir(cachePath): if include_page(file): items.extend(get_items_from_page(cachePath + file, sets)) items.sort(key=lambda x: x['name']) write_json(items, 'items')
def build_synonyms(): data = [] add(data, 'Armor Class', ['AC']) add(data, 'Armor-Piercing', ['Fortification Bypass']) add(data, 'False Life', ['Hit Points', 'Vitality', 'Lifeforce']) add(data, 'Speed', ['Striding']) add(data, 'Physical Sheltering', ['Physical Resistance Rating', 'PRR']) add(data, 'Magical Sheltering', ['Magical Resistance Rating', 'MRR']) add(data, 'Spell Focus Mastery', ['Spell DCs']) write_json(data, 'affix-synonyms')
def parse_item_pages(): with open("../site/src/assets/sets.json", 'r', encoding='utf8') as file: sets = json.load(file) cachePath = "./cache/items/" items = [] for file in os.listdir(cachePath): if include_page(file): items.extend(get_items_from_page(cachePath + file, sets)) items.sort(key=lambda x: x['name']) write_json(items, 'items')
def parse_set_page(): page = open('./cache/sets/Named_item_sets.html', "r", encoding='utf-8').read() soup = BeautifulSoup(page, 'html.parser') sets = get_sets_from_page(soup) slaversSets = parse_slavers_sets() sets = {**sets, **slaversSets} write_json(sets, 'sets')
def parse_minor_artifacts(): items = read_json('items') page = open('./cache/Minor_Artifact.html', "r", encoding='utf-8').read() soup = BeautifulSoup(page, 'html.parser') artifacts = get_artifacts_from_page(soup) for item in items: if item['name'] in artifacts: item['artifact'] = True write_json(items, 'items')
def build_crafting(): nearlyFinished = json.load( open('nearly-finished.json', "r", encoding='utf-8')) slavers = parse_slavers_crafting() augments = parse_augments() combined = {} combined.update(nearlyFinished) combined.update(slavers) combined.update(augments) write_json(combined, 'crafting')
def build_synonyms(): data = [] add(data, 'Armor Class', ['AC', 'Natural Armor', 'Protection', 'Shield', 'Armor Bonus']) add(data, 'Armor-Piercing', ['Fortification Bypass']) add(data, 'False Life', ['Hit Points', 'Vitality', 'Lifeforce']) add(data, 'Speed', ['Striding']) add(data, 'Physical Sheltering', ['Physical Resistance Rating', 'PRR']) add(data, 'Magical Sheltering', ['Magical Resistance Rating', 'MRR']) add(data, 'Spell Focus Mastery', ['Spell DCs']) add(data, 'Void Lore', ['Negative Spell Crit Chance']) add(data, 'Nullification', ['Negative Spell Power']) write_json(data, 'affix-synonyms')
def build_crafting(): nearlyFinished = json.load( open(f"{os.path.dirname(__file__)}/nearly-finished.json", "r", encoding='utf-8')) slavers = parse_slavers_crafting() augments = parse_augments() combined = {} combined.update(nearlyFinished) combined.update(slavers) combined.update(augments) write_json(combined, 'crafting')
def genre_add(): #open genres.json with open(filename) as json_file: data = json.load(json_file) temp = data['genres'] #define the data that will be appended genre = enter_genre() y = { "genre": genre } #check if the entered genre already exists. if yes, quits application genres_check(genre) # appending data to books.json temp.append(y) write_json(data, filename) print("\nGenre added.")
def build_affix_groups(): groups = [] parrying = get_all_saves() parrying.append('Armor Class') add(groups, 'Resistance', get_all_saves()) add(groups, 'Parrying', parrying) add(groups, 'Sheltering', ['Physical Sheltering', 'Magical Sheltering']) add(groups, 'Potency', [ 'Nullification', 'Radiance', 'Devotion', 'Corrosion', 'Combustion', 'Magnetic', 'Glaciation', 'Reconstruction', 'Impulse', 'Resonance' ]) add(groups, 'Combat Mastery', ['Vertigo', 'Stunning', 'Dazing', 'Sundering', 'Shatter']) add(groups, 'Alluring Skills Bonus', ['Bluff', 'Diplomacy', 'Haggle', 'Intimidate', 'Perform']) add(groups, 'Charisma Skills', ['Bluff', 'Diplomacy', 'Haggle', 'Intimidate', 'Perform']) add(groups, 'Intelligence Skills', ['Disable Device', 'Repair', 'Search', 'Spellcraft']) add(groups, 'Dexterity Skills', ['Balance', 'Hide', 'Move Silently', 'Open Locks', 'Tumble']) add(groups, 'Strength Skills', ['Jump']) add(groups, 'Wisdom Skills', ['Heal', 'Listen', 'Spot']) add(groups, 'Constitution Skills', ['Concentration']) add(groups, 'Well Rounded', [ 'Strength', 'Dexterity', 'Constitution', 'Intelligence', 'Wisdom', 'Charisma' ]) add(groups, 'Lifesealed', ['Deathblock', 'Negative Energy Absorption']) add(groups, 'Spell Focus Mastery', [ 'Evocation Focus', 'Necromancy Focus', 'Transmutation Focus', 'Enchantment Focus', 'Conjuration Focus', 'Abjuration Focus', 'Illusion Focus' ]) write_json(groups, 'affix-groups')
def author_add(): #open authors.json with open(filename) as json_file: data = json.load(json_file) temp = data['authors'] #define the data that will be appended author_surname = enter_author_name(surname) author_name = enter_author_name(name) author_birthday = enter_date(filename) author_gender = input("\nPlease enter the gender of the author: \n") y = { "surname": author_surname, "name": author_name, "birthday": author_birthday, "gender": author_gender, } #appending data to authors.json temp.append(y) write_json(data, filename) print("\nAuthor added.")
import re from pprint import pprint from write_json import write_json from read_json import read_json if __name__ == "__main__": img_name_pattern = '[a-zA-Z0-9\\-_]+\\|,(png|PNG|svg|SVG|jpeg|jpg|JPEG|JPG|gif|GIF)' path = "./before/test5.json" img_url_counts = read_json(path) new_url_obj = {} for img_url in img_url_counts.keys(): res = re.search(img_name_pattern, img_url) new_url_obj[res.group(0)] = img_url_counts[img_url] write_json(new_url_obj, path)
def parse_cannith(): assumedBonusTypeMap = get_most_common_bonus_type() wb = openpyxl.load_workbook('cannith-crafting.xlsx') for s in range(len(wb.sheetnames)): if wb.sheetnames[s] == 'Sheet1': break wb.active = s ws = wb.active itemTypeInfoList = [] for idx, cell in enumerate(ws[1], 0): if isinstance(cell.value, str): words = cell.value.split() if cell.value == 1: levelStart = idx elif cell.value == 34: levelEnd = idx elif cell.value in ['Min Level', 'Sort']: continue elif words[-1] in ['Prefix', 'Suffix', 'Extra']: itemType = ' '.join(words[0:-1]) itemTypeInfoList.append({'col': idx, 'itemType': itemType, 'affixLoc': words[-1]}) output = {} progression = {} itemTypes = {} output['progression'] = progression output['itemTypes'] = itemTypes output['bonusTypes'] = assumedBonusTypeMap rows = ws.iter_rows() next(rows) for row in rows: affix = row[0].value affix = affix.replace('Ins.', 'Insightful') affix = affix.title() affixes = [] if affix == 'Universal Spell Lore': for lore in ['Acid Lore', 'Cold Lore', 'Electricity Lore', 'Fire Lore', 'Force Lore', 'Light Lore', 'Negative Lore', 'Positive Lore', 'Repair Lore', 'Sonic Lore', 'Spell Lore']: affixes.append(lore) if affix == 'Spell Resistance (Sr)': affix = 'Spell Resistance' if affix == 'Resistance (Save)': affix = 'Resistance' if affix.startswith('Spell Focus: '): affix = affix.replace('Spell Focus: ', '') + ' Focus' if len(affixes) == 0: affixes.append(affix) progVals = [] for val in range(levelStart, levelEnd + 1): progVals.append(row[val].value) for affix in affixes: progression[affix] = progVals for itemInfo in itemTypeInfoList: isMarked = row[itemInfo['col']].value if isMarked and len(isMarked) > 0: if itemInfo['itemType'] not in itemTypes: itemTypes[itemInfo['itemType']] = {} if itemInfo['affixLoc'] not in itemTypes[itemInfo['itemType']]: itemTypes[itemInfo['itemType']][itemInfo['affixLoc']] = [] itemTypes[itemInfo['itemType']][itemInfo['affixLoc']].append(affix) # Only keep bonus types for things that are actually used by Cannith crafting delKeys = [] for k,v in assumedBonusTypeMap.items(): if k not in progression: delKeys.append(k) for k in delKeys: del assumedBonusTypeMap[k] write_json(output, 'cannith')