Hello,
Newb question here...
I'm trying to figure out how to push data from an electrical meter that is capable of sending XML to a server thru HTML POST.
I have a python script that Im interested in trying that can parse the XML to CSV, but for starters on the server end do I need to setup the server as an HTML server? Any recommendations on what to use? Like Appache or something similar setting up the server to accept the data push from the device to a server URL?
Thanks
my code here
Any web framework can accept xml as a post. To get started quickly, check out Flask:
http://flask.pocoo.org/
Introducing apache/nginx depends on what your goals are. If this is exposed to the internet, then maybe. If it's just running locally at your home/business and isn't accessible outside the intranet, that might not be needed.
If you want to put a little more work into the server end of it, Twisted is also a good networking library:
http://twistedmatrix.com/trac/
Quote:but for starters on the server end do I need to setup the server as an HTML server?
You can test all out locally
Flask as posted over has a build in web-server.
Here a demo.
#app.py
from flask import Flask, render_template
from bs4 import BeautifulSoup
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/xml-value/')
def my_link():
xml = '''\
<?xml version="1.0" encoding="UTF-8"?>
<note>
<value>4.567</value>
</note>'''
soup = BeautifulSoup(xml, 'lxml')
val = soup.find('value').text
return val
if __name__ == '__main__':
app.run(debug=True)
# In templates folder
#index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
<form>
<button formaction="/xml-value/">Get value</button>
</form>
</body>
</html>
python app.py
in browser
http://127.0.0.1:5000/
.
So getting a value from XML when push a button(call a Python function on the server side).
If you all new to this and web-development stuff with Python there is a learning process.
When it comes deploy,here some stuff that i like.
Gunicorn with
Nginx(better than and easier than Apache) on host
Digital Ocean.
There are host like
PythonAnywhere and AWS Lambda
Zappa,
they do all server side setup for you.