Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- city = "something"
- APIkey = "something"
- r = requests.post('http://api.openweathermap.org/data/2.5/weather?q='+city+'&APPID='APIkey)
- json_obj = r.json()
- print(json_obj['weather'][0]['description'])
- haze
- public class MessagesController : ApiController
- {
- public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
- {
- if (activity.Type == ActivityTypes.Message)
- {
- ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
- // calculate something for us to return
- string s = activity.Text;
- Weather w = new Weather();
- s = w.getWeather(s);
- // return our reply to the user
- Activity reply = activity.CreateReply(s);
- await connector.Conversations.ReplyToActivityAsync(reply);
- }
- else
- {
- HandleSystemMessage(activity);
- }
- var response = Request.CreateResponse(HttpStatusCode.OK);
- return response;
- }
- }
- public string getWeather(string s)
- {
- ProcessStartInfo pythonInfo = new ProcessStartInfo();
- Process python;
- StreamReader sr;
- pythonInfo.FileName = @"somepathpython.exe";
- pythonInfo.Arguments = @"somepathfile.py";
- pythonInfo.CreateNoWindow = false;
- pythonInfo.UseShellExecute = false;
- pythonInfo.RedirectStandardOutput = true;
- Debug.WriteLine("Python Starting");
- python = Process.Start(pythonInfo);
- Debug.WriteLine("Python Started");
- sr = python.StandardOutput;
- Debug.WriteLine("passed standard output to sr");
- string text = sr.ReadLine();
- Debug.WriteLine(sr.ReadLine());
- Debug.WriteLine(text);
- python.WaitForExit();
- python.Close();
- sr.Close();
- return text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement