Advertisement
xIntangible

Untitled

Jun 15th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. import json
  2. import sqlite3
  3.  
  4. #dictionary that tells where to get the hashes for each table
  5. hash_dict = {'DestinyActivityDefinition':'activityHash','DestinyActivityTypeDefinition':'activityTypeHash','DestinyClassDefinition': 'classHash','DestinyGenderDefinition':'genderHash','DestinyInventoryBucketDefinition':'bucketHash','DestinyInventoryItemDefinition': 'itemHash','DestinyProgressionDefinition': 'progressionHash','DestinyRaceDefinition': 'raceHash','DestinyTalentGridDefinition': 'gridHash','DestinyUnlockFlagDefinition': 'flagHash', 'DestinyHistoricalStatsDefinition': 'statId','DestinyDirectorBookDefinition': 'bookHash','DestinyStatDefinition': 'statHash','DestinySandboxPerkDefinition': 'perkHash','DestinyDestinationDefinition': 'destinationHash','DestinyPlaceDefinition':'placeHash','DestinyActivityBundleDefinition':'bundleHash','DestinyStatGroupDefinition': 'statGroupHash','DestinySpecialEventDefinition':'eventHash','DestinyFactionDefinition':'factionHash','DestinyVendorCategoryDefinition':'categoryHash','DestinyEnemyRaceDefinition':'raceHash','DestinyScriptedSkullDefinition':'skullHash','DestinyGrimoireCardDefinition': 'cardId'}
  6.  
  7. def build_data():
  8.     #connect to the manifest
  9.     con = sqlite3.connect('Manifest.content')
  10.     #create a cursor object
  11.     cur = con.cursor()
  12.  
  13.     #get a list of all table
  14.     cur.execute("SELECT name from sqlite_master where type = 'table'")
  15.     #this actually returns a list of tuples,
  16.     #where the first item in the tuple is the Table Name, the second is empty
  17.     all_tables = cur.fetchall()
  18.    
  19.    
  20.     all_data = {}
  21.     #for every table name
  22.     for table in all_tables:
  23.         table_name = table[0]
  24.         #if the location of the hashes is in our hash_dict
  25.         if table_name in hash_dict.keys():
  26.             #get a list of all the jsons from the table
  27.             cur.execute('SELECT json from '+table_name)
  28.            
  29.             #again, tuples: the first item is our json
  30.             items = cur.fetchall()
  31.            
  32.             #create a list of jsons
  33.             item_jsons = [json.loads(item[0]) for item in items]
  34.            
  35.             #create a dictionary with the hashes as keys
  36.             #and the jsons as values
  37.             item_dict = {}
  38.             hash = hash_dict[table_name]
  39.             for item in item_jsons:  
  40.                 item_dict[item[hash]] = item
  41.        
  42.             #add that dictionary to our all_data using the name of the table
  43.             #as a key.
  44.             all_data[table_name] = item_dict    
  45.  
  46.     return all_data
  47.  
  48. #call function  
  49. all_data = build_data()
  50.  
  51. #Gjallarhorn
  52. gally = all_data['DestinyInventoryItemDefinition'][1274330687]
  53. print gally['itemName']
  54. print gally['itemTypeName']
  55. print gally['itemDescription']
  56.  
  57. OUTPUT:
  58. >> Gjallarhorn
  59. >> Rocket Launcher
  60. >> "If there is beauty in destruction, why not also in its delivery?" - Feizel Crux
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement