libdo

Untitled

Sep 29th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import os
  3. import re
  4.  
  5. DIRECTORY = os.path.dirname(os.path.realpath(__file__))
  6.  
  7. UNITS = "http://optc-db.github.io/common/data/units.js"
  8.  
  9.  
  10. def decode(link=""):
  11.     if link == "":
  12.         raise Exception("Empty link provided")
  13.  
  14.     url = link.replace("http://", "").split("/")
  15.  
  16.     if url[0] != "optc-db.github.io" or url[1] != "damage":
  17.         raise Exception("Invalid link provided")
  18.  
  19.     chars = re.search(r'transfer/D([^C]+)C', "/".join(url[-2:])).groups(1)[0].split(",")
  20.  
  21.     char_name = []
  22.  
  23.     r = requests.get(UNITS)
  24.  
  25.     _chars = r.text.split('\n')
  26.  
  27.     for char in chars:
  28.         char_id = int(char.split(":")[0])
  29.         info = _chars[char_id]
  30.  
  31.         items = re.findall(r'"([^"]+)"', info)
  32.         character_name = "{2} - [{0}](/{1})".format(items[0], items[1].lower(), char_id)
  33.  
  34.         char_name.append(character_name)
  35.  
  36.     print(char_name)
  37.  
  38. decode("http://optc-db.github.io/damage/#/transfer/D1751:99:100:0:0,1751:99:100:0:0,831:99,1043:99,575:99,984:99C10,10B0D0E0Q0L0G0R0S100H")
Add Comment
Please, Sign In to add comment