If I understand you correctly, you need HTTP requests?
It took me a couple of days recently to get Renpy and the requests library working together, but in the end I gave up. If you can do it, let me know. I didn't have a specific goal in mind, I just wanted to see if I could use Renpy to query a site and get data from it, like weather. I haven't delved into the requests library, but you need something like that:
Code: Select all
init python:
import requests
URL = 'https://lemmasoft.renai.us/forums/'
response = requests.get(URL)
status = str(response.status_code)
screen test:
vbox:
text status # 200. This means that we got an answer and everything is fine
We can also add a few lines and get an HTML page:
Code: Select all
init python:
import requests
URL = 'https://lemmasoft.renai.us/forums/'
response = requests.get(URL)
text = response.text
status = str(response.status_code)
chars = '{}[]'
result = text.translate(str.maketrans('', '', chars))
screen test:
vbox:
text str(result)
The result will be this:
Now the data is in unformatted form, so it would be good to put it in order with other libraries or get specific data via tag, class, ID, get several tags, all of them, or some specific one. But unfortunately Renpy refuses to work with pyowm, bs4, lxml. I have all this installed (CMD --> pip install ...), it all works fine in pure python file, but Renpy gives error "ModuleNotFoundError". Maybe renpy needs a special PATH, I don't know... My PATH is set to installed Python. But maybe renpy doesn't support working with these libraries. I didn't post a question about this topic on the forum because I didn't expect to get an answer, as this topic is specialized and narrowly focused and hardly anyone knows what the issue is. If anyone should ask PyTom, but I was too embarrassed to do so.
If someone asks me "why do you want it, kid?" I have nothing to say... Because it's just curiosity.
In your case you need:
Code: Select all
URL = 'http://yourserver.com/yourgame/index.html'
response = requests.get(URL)
text = response.text
screen test:
text str(text)
Result:
Code: Select all
<html><head></head><body><!-- vbe --></body></html>
As you can see, the HTML page is empty. To get anything out of it, you can refer to a tag, such as <p> or <a> or by class name (e.g. ".name" or by id = "#name").
The libraries listed above are needed just for these tasks, but they don't work for me...
You can get the data you want through a slice of the result or through a search for occurrences in a string.