Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import requests
  2. city = "something"
  3. APIkey = "something"
  4. r = requests.post('http://api.openweathermap.org/data/2.5/weather?q='+city+'&APPID='APIkey)
  5. json_obj = r.json()
  6. print(json_obj['weather'][0]['description'])
  7.  
  8. haze
  9.  
  10. public class MessagesController : ApiController
  11. {
  12. public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
  13. {
  14. if (activity.Type == ActivityTypes.Message)
  15. {
  16. ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
  17. // calculate something for us to return
  18. string s = activity.Text;
  19. Weather w = new Weather();
  20. s = w.getWeather(s);
  21. // return our reply to the user
  22. Activity reply = activity.CreateReply(s);
  23. await connector.Conversations.ReplyToActivityAsync(reply);
  24. }
  25. else
  26. {
  27. HandleSystemMessage(activity);
  28. }
  29. var response = Request.CreateResponse(HttpStatusCode.OK);
  30. return response;
  31. }
  32. }
  33.  
  34. public string getWeather(string s)
  35. {
  36. ProcessStartInfo pythonInfo = new ProcessStartInfo();
  37. Process python;
  38. StreamReader sr;
  39. pythonInfo.FileName = @"somepathpython.exe";
  40. pythonInfo.Arguments = @"somepathfile.py";
  41. pythonInfo.CreateNoWindow = false;
  42. pythonInfo.UseShellExecute = false;
  43. pythonInfo.RedirectStandardOutput = true;
  44. Debug.WriteLine("Python Starting");
  45. python = Process.Start(pythonInfo);
  46. Debug.WriteLine("Python Started");
  47. sr = python.StandardOutput;
  48. Debug.WriteLine("passed standard output to sr");
  49. string text = sr.ReadLine();
  50. Debug.WriteLine(sr.ReadLine());
  51. Debug.WriteLine(text);
  52. python.WaitForExit();
  53. python.Close();
  54. sr.Close();
  55. return text;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement