LoginSignup
0
0

More than 1 year has passed since last update.

C#からPythonでWebApiのデータを取得する

Last updated at Posted at 2022-06-29

C#からPythonでWebApiのdataを取得する

ProcessのOutputDataReceivedとDataReceivedEventHandlerを使ってデータを受信します

using System;
using System.Diagnostics;

Process process = new Process();
process.StartInfo.FileName = "/usr/bin/python3.6";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.EnableRaisingEvents = true;
//パスを指定する
process.StartInfo.Arguments = "/test.py 7203";

process.Exited += (s, evt) => {
	process?.Dispose();
};

process.OutputDataReceived += new DataReceivedEventHandler((_sender, _e) =>
	{

		if (!String.IsNullOrEmpty(_e.Data))
		{
 		   Console.WriteLine(_e.Data);
		}
	}
);

process.Start();
process.BeginOutputReadLine();
test.py
import json
import sys
import investpy

# pip install investpy

args = sys.argv

#トヨタ自動車 7203
code = args[0]
stock_data = investpy.get_stock_historical_data(as_json=True,stock=code, country='japan', from_date='01/02/2021', to_date='28/03/2021')

print(stock_data)

Visual Studio CodeでLinux C# Guiアプリを開発するへ続く

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0