Web Apps


uiWebPrevious12345678910uiWebNext

#136 [en] 

Nudge
Anyone wrote Python or C code that uses GET for the XMLs?

There was py-ryzom-api for python, but its abandoned and no source in github anymore.

I have not heard of anyone doing it in C.

---

Hello!

#137 [en] 

Thanks Karu.

#138 [en] 

In Python, requesting the xml from the server would be trivial with the "requests" library, then there are xml/html parsing libraries like BeautifulSoup + lxml.

What exactly are you trying to accomplish? :)

---


My home is always sweet Yrkanis..

#139 [en] 

Right, I am not a py programmer so C or assembler would do better for me ;),... I would even take Fortran or Pascal.

I am trying to get all items and details in inventory for a toon, then massage it into something magical.

I have been able to get it using this:
import sys
import xml.etree.ElementTree as ET
import requests
RYZ_API_ENDPOINT = "http://api.ryzom.com/character.php"
ryz_api_key = "abracadabraverylongcodewithnumbersandlettersstuff"
RYZ_PARAMS = {'apikey': ryz_api_key}
r = requests.get(url = RYZ_API_ENDPOINT, params = RYZ_PARAMS)
print(r.status_code)
print(r.status_code == requests.codes.ok)
print(r.headers['content-type'])
print(r.encoding)
print(r.url)
ryz_toon = ET.parse(r.text)
for elem in ryz_toon.iter():
 print ("%s: '%s'\n\r", elem.tag, elem.text)
Just wondered if there is a better, or pre-made set of libs.

Ultimately, not much different in C either.  there are libraries to get a HTTP/S responses back, and also XML parsers.

Last edited by Nudge (6 years ago)

#140 [en] 

I still prefer bs4, maybe it's because it was my first contact with html/xml parsers in Python. Also, it makes it easy to navigate the xml tree quite easily.

Here's a crude example that will print out all of a character's fames:

import sys
import requests
from bs4 import BeautifulSoup

url = "http://api.ryzom.com/character.php?apikey=xxxxxxxxxx"
r = requests.get(url)
data = r.text

soup = BeautifulSoup(data, 'xml')

#find all items
items = soup.find("fame").find_all()

for item in items:
print(item.name+" "+item.text+"\n")


But yes, ultimately not much different than your example.

Edited 2 times | Last edited by Laoviel (6 years ago)

---


My home is always sweet Yrkanis..

#141 [en] 

Python example to get api data, convert to json, and pretty print:

first install:
pip3 install requests xmltodict


#!/usr/bin/env python3

import json, requests, time, xmltodict

api = 'http://api.ryzom.com/time.php?format=xml'

response = requests.get(api)
jsondata = xmltodict.parse(response.text)
print(json.dumps(jsondata, sort_keys = True, indent = 4))

Last edited by Tgwaste (2 years ago)

---

Tgwaste
uiWebPrevious12345678910uiWebNext
 
Last visit Sunday, 1 December 16:43:10 UTC
P_:G_:PLAYER

powered by ryzom-api