Small python project [Get Info]

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Small python project [Get Info]

      Python Source Code

      1. # Imports voor afhalen XML en voor de XML te verwerken
      2. import urllib.parse,urllib.request
      3. import xml.etree.ElementTree as ET
      4. # Deze halen de XML files van het internet (Downloaden van XML files)
      5. data= urllib.request.urlopen('https://SERVER.ogame.gameforge.com/api/universe.xml')
      6. data2= urllib.request.urlopen('https://SERVER.ogame.gameforge.com/api/players.xml')
      7. data3= urllib.request.urlopen('https://SERVER.ogame.gameforge.com/api/alliances.xml')
      8. # De xml files zijn nu echter nog bytes $
      9. # Deze moeten nu omgezet worden naar strings dat doen we hier
      10. root = ET.fromstring(data.read().decode("utf-8"))
      11. root2 = ET.fromstring(data2.read().decode("utf-8"))
      12. root3 = ET.fromstring(data3.read().decode("utf-8"))
      13. #De spelersnaam
      14. spelerNaam = "PLAYER_NAME"
      15. # Hier zetten we de spelersnaam om naar de spelers ID
      16. # We geven de waarde van de ID terug
      17. def function1():
      18. for player in root2.findall('player'):
      19. if player.get('name')==spelerNaam:
      20. return player.get('id')
      21. # Laat de ID op het scherm verschijnen
      22. print(function1())
      23. # Dit gaat de planeten zoeken adhv de ID die we hiervoor hebben gevonden
      24. for planet in root.findall('planet'):
      25. if planet.get('player')==function1():
      26. id = planet.get('coords')
      27. name = planet.get('name')
      28. print (id, name)
      29. # Zoekt de speler/planeet/alliantie
      30. def function3():
      31. with open('LIST.txt') as f:
      32. content = f.read().splitlines()
      33. for planet in root.findall('planet'):
      34. id = planet.get('coords')
      35. name = planet.get('name')
      36. for word in content:
      37. if word.lower() in name.lower():
      38. print("PLANEET " ,id, name)
      39. for player in root2.findall('player'):
      40. name = player.get('name')
      41. id = player.get('id')
      42. for word in content:
      43. if word.lower() in name.lower():
      44. print("SPELER " ,id, name)
      45. for alliance in root3.findall('alliance'):
      46. name = alliance.get('name')
      47. id = alliance.get('id')
      48. for word in content:
      49. if word.lower() in name.lower():
      50. print("ALLIANTIE " ,id, name)
      51. function3()
      Display All
      I'm still working on it but I would love to use it as is already.

      The post was edited 2 times, last by Takumi ().