text: import json
  from lxml import etree
  import os
  from update_data import database_update
  
  def all_version():
      tree = etree.parse("database/wp_versions.xml")
      doc = tree.getroot()
      versions = []
      for elem in doc.findall('file/hash/'):
          versions.append(elem.text)
      version_n = set(versions)
  
      return version_n
  
  def wordpress_exploit_create():
  
      jsonObject = ""
      with open('database/wordpresses.json') as data_file:
          jsonObject = json.load(data_file)
  
      versions = all_version()
      for v in versions:
          try:
              for vuln in jsonObject[v]["vulnerabilities"]:
                  f = open('exploits/wordpress_version/'+vuln['title']+'.txt', 'w')
                  f.write("%s : %s - ID:%s" % (vuln['vuln_type'], vuln['title'] , vuln['id']) )
                  f.write("\t\nFixed in %s"% vuln['fixed_in'])
                  f.write("")
                  f.write("\t\nReferences:")
                  for refkey in vuln['references'].keys():
                      for ref in vuln['references'][refkey]:
  
                          if refkey != 'url':
                              f.write( "\t\t\n - %s %s" % (refkey.capitalize(), ref))
                          else:
                              f.write("\t\t\n - %s" %ref)
  
                  f.write("")
                  f.close()
          except:
                  pass
  
  def plugins_exploits_create():
  
      jsonObject = ""
      with open('database/plugins.json') as data_file:
          jsonObject = json.load(data_file)
  
      for plugins in jsonObject.keys():
          if jsonObject[plugins]['latest_version'] != None:
              try:
                  for vuln in jsonObject[plugins]["vulnerabilities"]:
                      f = open('exploits/wordpress_plugins/'+vuln['title']+'.txt', 'w')
                      f.write("%s : %s - ID:%s" % (vuln['vuln_type'], vuln['title'] , vuln['id']) )
                      f.write("\t\nFixed in %s"% vuln['fixed_in'])
                      f.write("")
                      f.write("\t\nReferences:")
                      for refkey in vuln['references'].keys():
                          for ref in vuln['references'][refkey]:
  
                              if refkey != 'url':
                                  f.write( "\t\t\n - %s %s" % (refkey.capitalize(), ref))
                              else:
                                  f.write("\t\t\n - %s" %ref)
  
                      f.write("")
                      f.close()
              except:
                  pass 
                          
  def themes_exploits_create():
  
      jsonObject = ""
      with open('database/themes.json') as data_file:
          jsonObject = json.load(data_file)
  
      for themes in jsonObject.keys():
          if jsonObject[themes]['latest_version'] != None:
              try:
                  for vuln in jsonObject[themes]["vulnerabilities"]:
                      f = open('exploits/wordpress_themes/'+vuln['title']+'.txt', 'w')
                      f.write("%s : %s - ID:%s" % (vuln['vuln_type'], vuln['title'] , vuln['id']) )
                      f.write("\t\nFixed in %s"% vuln['fixed_in'])
                      f.write("")
                      f.write("\t\nReferences:")
                      for refkey in vuln['references'].keys():
                          for ref in vuln['references'][refkey]:
  
                              if refkey != 'url':
                                  f.write( "\t\t\n - %s %s" % (refkey.capitalize(), ref))
                              else:
                                  f.write("\t\t\n - %s" %ref)
  
                      f.write("")
                      f.close()
              except:
                  pass 
                  
  def main():
      
      dir = {"database","exploits","exploits/wordpress_plugins/","exploits/wordpress_themes/","exploits/wordpress_version/"}
      for d in dir:
          if not os.path.exists(d):
              os.makedirs(d)
      database_update()
      wordpress_exploit_create()
      plugins_exploits_create()
      themes_exploits_create()
  
  if __name__ == '__main__':
      main()
  
  