Created
March 20, 2019 14:14
-
-
Save David256/236d615922a10e3a0e2d90d90f008e1c to your computer and use it in GitHub Desktop.
A simple http server that call a function a return data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| # -*- coding: utf-8 -*- | |
| from flask import request, Flask | |
| from lstm_trabajador import trabajar | |
| app = Flask(__name__) | |
| @app.route("/preguntar", methods=["POST"]) | |
| def preguntar(): | |
| dias = request.form.get("dias") | |
| dias = int(dias) | |
| predicciones = trabajar(dias, "noche") | |
| print("Enviando....", predicciones) | |
| return ";".join([str(int(n*1000000)) for n in predicciones]) | |
| if __name__ == '__main__': | |
| app.run(port=8080) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace WebApplicationSimple.app | |
| { | |
| public partial class WebForm : Page | |
| { | |
| /** | |
| * Hace una pregunta a otro host | |
| */ | |
| private List<double> Preguntar(int dias, int tipo) | |
| { | |
| String url = ""; | |
| if (tipo == 0) | |
| url = "http://localhost:8080/preguntar.noche"; | |
| else if (tipo == 1) | |
| url = "http://localhost:8080/preguntar.4000"; | |
| else if (tipo == 2) | |
| url = "http://localhost:8080/preguntar.5000"; | |
| HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; | |
| request.Method = "POST"; | |
| request.ContentType = "application/x-www-form-urlencoded"; | |
| String postData = "dias=" + dias.ToString(); | |
| byte[] byteArray = Encoding.UTF8.GetBytes(postData); | |
| request.ContentLength = byteArray.Length; | |
| Stream dataStream; | |
| try | |
| { | |
| dataStream = request.GetRequestStream(); | |
| } catch(Exception e) { | |
| return null; | |
| } | |
| dataStream.Write(byteArray, 0, byteArray.Length); | |
| dataStream.Close(); | |
| WebResponse response; | |
| try | |
| { | |
| response = request.GetResponse(); | |
| } catch(Exception e) { | |
| return null; | |
| } | |
| Console.WriteLine(((HttpWebResponse)response).StatusDescription); | |
| dataStream = response.GetResponseStream(); | |
| StreamReader reader = new StreamReader(dataStream); | |
| string responseFromServer = reader.ReadToEnd(); | |
| Console.WriteLine(responseFromServer); | |
| reader.Close(); | |
| dataStream.Close(); | |
| response.Close(); | |
| List<double> resultados = new List<double>(); | |
| String[] separados = responseFromServer.Split(';'); | |
| for (int i = 0; i < separados.Count(); i++) | |
| { | |
| resultados.Add(double.Parse(separados[i])); | |
| } | |
| return resultados; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment