Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SROUCE: https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/630376-d3-pickit-importer.html
- # Make two new directories
- # build_html
- # output
- # Browse to builds you want on diablofans, 'Save page as' html only into 'build_html' directory and run pickit.py
- # builds are in 'output' each in its own ini {CLASS}-{TITLE} taken from the html
- # USER SETTINGS
- fourthree = "three"
- # fourthree = "four"
- # DO NOT change BELOW UNLESS YOU KNOW HOW TO change
- import json
- import requests
- import urllib.request, urllib.error, urllib.parse
- from bs4 import BeautifulSoup
- from collections import OrderedDict
- import os
- # GLOBAL VARIABLES */
- soup = None
- pickitlist = ""
- # Build Types
- # Build ini with essential items or just build.
- # i broke this. Just copy paste like your reddit shit posts.
- buildtype = "build"
- FANS_BASEURL = 'http://www.diablofans.com/builds/'
- with open(r'data\itemlist.json', 'r') as f:
- itemList = json.load(f)
- with open(r'data\statlist2.json', 'r') as f1:
- statList = {int(k): v for k, v in json.load(f1).items()}
- with open(r'data\typelist.json', 'r') as f2:
- typeList = json.load(f2)
- def switch(importance):
- if importance == "1":
- return "Required"
- elif importance == "2":
- return "Recommended"
- elif importance == "3":
- return "Adequate"
- def getiteminfos(name):
- for item in itemList:
- if item['name'].strip() == name:
- return item['type']
- def getitemslot(slot):
- global soup
- slotobj = {}
- itemarr = []
- statarr = []
- itemslot_soup = soup.select('#item-{} li[data-item-id]'.format(slot))
- for item in itemslot_soup:
- name = item.find('a').get_text()
- importance = switch(item.get('data-item-importance')[0])
- _type = getiteminfos(name)
- print('NAME={} | TYPE={} | SLOT={}'.format(name, _type, slot))
- itemdetails = {
- 'name': name,
- 'type': _type,
- 'importance': importance,
- }
- itemarr.extend([itemdetails])
- statslot_soup = soup.select('#item-{} .item-stat a'.format(slot))
- for stats in statslot_soup:
- stattitle = stats.get('title')
- stattitle_soup = BeautifulSoup(stattitle, 'html.parser')
- statarr.extend([stattitle_soup.get_text().rsplit(':', 1)[0]])
- slotobj['items'] = itemarr
- slotobj['stats'] = statarr
- return slotobj
- def getitemtype(name):
- _type = "undefined"
- for item in itemList:
- # print 'item in itemlist: {}'.format(item)
- if name['name'] == item['name']:
- _type = item['type']
- pickityype = typeList[_type]
- return pickityype
- def getpickitstat(stat):
- global statList
- for arr in statList:
- pickit = statList[arr][1]
- full = statList[arr][0]
- if full == stat:
- return pickit
- def generatestring(item):
- global pickitlist
- global fourthree
- k = 0
- string = ""
- while k < len(item['items']):
- name = item['items'][k]['name']
- statcount = len(item['stats'])
- stats = item['stats']
- atleaststring = generateatleaststring(statcount, stats)
- _type = getitemtype(item['items'][k])
- if not _type:
- _type = 'fucking-errors-man'
- string += _type + ' = name=' + name + ' ' + atleaststring + '\n'
- # string += '\n'
- k += 1
- pickitlist += string
- def generatecubestring(name):
- global pickitlist
- _type = None # err is err
- for item in itemList:
- if name == item['name']:
- _type = item['type']
- pickittype = typeList[_type]
- _type = pickittype
- pickitlist += _type + ' = name=' + name + ' ' + '& can_cubed=1 & cubed=0\n'
- def generateatleaststring(statcount, stats):
- global fourthree
- string = ''
- if not stats or statcount == '0':
- return string
- i = 0
- while i < len(stats):
- pickit = getpickitstat(stats[i])
- if pickit == 'not_imp':
- stats.pop(i)
- i -= 1
- else:
- i += 1
- string += '& at_least['
- if fourthree == '4':
- string += str(statcount) + ', '
- else:
- string += str(statcount - 1) + ', '
- j = 0
- while j < len(stats):
- pickit = getpickitstat(stats[j])
- if not pickit:
- pickit = 'fucking-errors-man'
- string += pickit
- if j < len(stats) - 1:
- string += ', '
- j += 1
- else:
- string += ']'
- j += 1
- return string
- def gen_build(html):
- global fourthree, buildtype, soup, pickitlist
- page = open(html, 'r')
- soup = BeautifulSoup(page, 'html.parser')
- resobj = OrderedDict()
- resobj['build_name'] = soup.find(attrs={'class': 'build-title'}).get_text()
- resobj['build_url'] = FANS_BASEURL + soup.find(attrs={'class': 'd3build-bbcode-button'}).get('data-build-id')
- resobj['build_class'] = soup.find(attrs={'class': 'classBadge'}).get('title')
- resobj['item_head'] = getitemslot('head')
- resobj['item_shoulders'] = getitemslot('shoulders')
- resobj['item_amulet'] = getitemslot('amulet')
- resobj['item_torso'] = getitemslot('torso')
- resobj['item_wrists'] = getitemslot('wrists')
- resobj['item_hands'] = getitemslot('hands')
- resobj['item_waist'] = getitemslot('waist')
- resobj['item_legs'] = getitemslot('legs')
- resobj['item_feet'] = getitemslot('feet')
- resobj['item_rings'] = getitemslot('rings')
- resobj['item_weapon'] = getitemslot('weapon')
- resobj['item_offhand'] = getitemslot('offhand')
- # buildnumber = 'DH-UE-MultiShot'
- buildnumber = '%s-%s' % (resobj['build_class'], resobj['build_name'])
- if soup.select('#kanai-weapon .db-title span'):
- resobj['kanai_weapon'] = soup.select('#kanai-weapon .db-title span')[0].get_text()
- print(('Kanai Weapon Slot | NAME={}'.format(resobj['kanai_weapon'])))
- if soup.select('#kanai-armor .db-title span'):
- resobj['kanai_armor'] = soup.select('#kanai-armor .db-title span')[0].get_text()
- print('Kanai Armor Slot | NAME={}'.format(resobj['kanai_armor']))
- if soup.select('#kanai-jewelry .db-title span'):
- resobj['kanai_jewelry'] = soup.select('#kanai-jewelry .db-title span')[0].get_text()
- print('Kanai Jewelry Slot | NAME={}'.format(resobj['kanai_jewelry']))
- if buildtype == "full":
- with open(r'data\essentials.txt', 'r') as essentials:
- with open('pickit_sc_70.ini', 'w') as a_file:
- a_file.write(essentials.read())
- a_file.write('\n')
- pickitlist = ';||||' + resobj['build_class'] + '-Build: ' + resobj['build_name'] + ' Link: ' + resobj[
- 'build_url'] + ' ||||\n'
- for entry in resobj:
- if entry.startswith('item'):
- # print(resobj[entry])
- generatestring(resobj[entry])
- if entry.startswith('kanai'):
- generatecubestring(resobj[entry])
- pickitlist += ';|||| End of Build ||||'
- print('')
- if buildtype == "full":
- with open(r'data\essentials.txt', 'r') as essentials:
- with open('output/pickit_sc_70.ini', 'w') as a_file:
- a_file.write(essentials.read())
- a_file.write('\n')
- with open('output/pickit_sc_70.ini', 'a') as a_file:
- pickitlist += '\n'
- a_file.write(pickitlist)
- if buildtype == "full":
- with open(r'data\essentials2.txt', 'r') as essentials2:
- with open('output/pickit_sc_70.ini', 'a') as a_file:
- a_file.write(essentials2.read())
- print('INFO | save successful')
- else:
- with open('output/' + buildnumber + '.ini', 'w') as a_file:
- pickitlist += '\n'
- a_file.write(pickitlist)
- print('INFO | save successful')
- if __name__ == '__main__':
- for build in os.listdir(r'build_html'):
- gen_build(os.path.join('build_html', build))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement