URL http localhost xxxxdefault aspx stock2330 stock2330 http

  • Slides: 27
Download presentation

URL參數 http: //localhost: xxxx/default. aspx? stock=2330 ? 後面的stock=2330就是我們要傳遞的參數 這次我們以http post來做說明

URL參數 http: //localhost: xxxx/default. aspx? stock=2330 ? 後面的stock=2330就是我們要傳遞的參數 這次我們以http post來做說明

前端範例(取得URL參數) function get. Url. Parameter(s. Param) { var s. Page. URL = window. location.

前端範例(取得URL參數) function get. Url. Parameter(s. Param) { var s. Page. URL = window. location. search. substring(1), s. URLVariables = s. Page. URL. split('&'), s. Parameter. Name, i; for (i = 0; i < s. URLVariables. length; i++) { s. Parameter. Name = s. URLVariables[i]. split('='); if (s. Parameter. Name[0] === s. Param) { return s. Parameter. Name[1] === undefined ? true : decode. URIComponent(s. Parameter. Name[1]); } } }

前端範例(AJAX) function Get. Stock. Info() { var stock = get. Url. Parameter('stock'); $. ajax({

前端範例(AJAX) function Get. Stock. Info() { var stock = get. Url. Parameter('stock'); $. ajax({ type: 'post', url: 'Data. Handler. ashx', data: { action: 'Get. Stock. Info', stock: stock, }, success: function (data) { var obj = j. Query. parse. JSON(data); $('#txt_stock_info')[0]. text. Content = obj[0]. Result; }, error: function () { alert('資料取得失敗'); } }) }

後端範例 抓取POST或GET的方法 string s. Action = (context. Request. Form["action"] != null) ? context. Request.

後端範例 抓取POST或GET的方法 string s. Action = (context. Request. Form["action"] != null) ? context. Request. Form["action"] : context. Request["action "]; 連線到API抓取資料 string target. Url = "http: //60. 250. 174. 158/pepperapi/analyze_stock. ashx? stock=" + s. Stock ; Http. Web. Request request = Http. Web. Request. Create(target. Url) as Http. Web. Request; request. Method = "GET"; request. Content. Type = "application/x-www-form-urlencoded"; request. Timeout = 30000; string result = ""; // 取得回應資料 using (Http. Web. Response response = request. Get. Response() as Http. Web. Response) { using (Stream. Reader sr = new Stream. Reader(response. Get. Response. Stream())) { result = sr. Read. To. End(); } } context. Response. Write(result ); //回傳前端

Pepper-Python-init 新增一個python script 來做程式初始化設定相關參數 def __init__(self): Generated. Class. __init__(self) self. tts = ALProxy('ALText. To.

Pepper-Python-init 新增一個python script 來做程式初始化設定相關參數 def __init__(self): Generated. Class. __init__(self) self. tts = ALProxy('ALText. To. Speech') self. web = ALProxy('ALTablet. Service') self. web. enable. Wifi() wifstatut = self. web. get. Wifi. Status() self. tts. Stop = ALProxy('ALText. To. Speech', True) #Create self. path = ALFrame. Manager. get. Behavior. Path(self. behavior. Id) + "/lib" if self. path not in sys. path: sys. path. append(self. path)

Pepper-Python-init def on. Load(self): self. b. Is. Running = False self. ids = []

Pepper-Python-init def on. Load(self): self. b. Is. Running = False self. ids = [] self. memory = ALProxy("ALMemory")

Pepper-Python-init(載入前50大權值股名稱 ) def on. Input_on. Start(self, p): now. URL = ‘http: //60. 250. 174.

Pepper-Python-init(載入前50大權值股名稱 ) def on. Input_on. Start(self, p): now. URL = ‘http: //60. 250. 174. 158/pepperapi/query_stock. ashx? stocktype=taiwan 50' reddit_file = urllib 2. urlopen(now. URL) encodedjson = json. load(reddit_file, encoding='utf-8') ouput = '' for index in range(len(encodedjson)): ouput += encodedjson[index]["Stock. Name"]. encode('utf-8', 'ignore')+ '; ' tmparray = ouput. split('; ') self. memory. insert. Data("stock. Names", tmparray)

Pepper-Python-收音 def on. Input_on. Start(self): from threading import Lock self. mutex. acquire() if(self. b.

Pepper-Python-收音 def on. Input_on. Start(self): from threading import Lock self. mutex. acquire() if(self. b. Is. Running): self. mutex. release() return self. b. Is. Running = True try: if self. asr: self. asr. set. Visual. Expression(self. get. Parameter("Visual expression")) self. asr. push. Contexts() self. has. Pushed = True if self. asr: ouput = '' ouput = self. memory. get. Data('stock. Names') self. asr. set. Vocabulary( ouput, self. get. Parameter("Enable word spotting"))

Pepper-Python 新增一個Python Script 輸入處這樣設定

Pepper-Python 新增一個Python Script 輸入處這樣設定

Pepper-Python 點擊兩下進入程式畫面 def on. Load(self): self. b. Is. Running = False self. ids =

Pepper-Python 點擊兩下進入程式畫面 def on. Load(self): self. b. Is. Running = False self. ids = [] self. memory = ALProxy("ALMemory") def on. Unload(self): for id in self. ids: try: self. tts. Stop. stop(id) except: pass while( self. b. Is. Running ): time. sleep( 1. 5 )

Pepper-Python def on. Input_on. Start(self, p): Price = '' p. Data = self. memory.

Pepper-Python def on. Input_on. Start(self, p): Price = '' p. Data = self. memory. get. Data('stock. Names') p = self. type. Conversion(p) try: for index in range(len(p. Data)): if(p == self. type. Conversion(p. Data[index])): try: stockname = p. Data[index] now. URL = 'http: //60. 250. 174. 158/pepperapi/analyze_stock. ashx? stock=' + p. Data[index] web. URL = 'http: //localhost/default. aspx? stock='+ p. Data[index] reddit_file = urllib 2. urlopen(now. URL) #convert to string: encodedjson = json. load(reddit_file, encoding='utf-8') Price += encodedjson[0]["Result"]. encode('utf-8', 'ignore')+ '; ' self. web. show. Webview() self. web. load. Url(web. URL) movement = "disabled" text. Param = p. Data[index] if movement == "disabled": text. Param = "^start({0}) {1} ^wait({0})". format('Stand/Emotions/Positive/Excited_1', text. Param) sentence = "RSPD=110 " sentence += "VCT=110 " sentence += Price sentence += "RST " id = self. tts. post. say(str(sentence)) self. ids. append(id)

C# 串API取得各項數值 case "Get. Stock. Info": { string target. Url = "http: //60. 250.

C# 串API取得各項數值 case "Get. Stock. Info": { string target. Url = "http: //60. 250. 174. 158/pepperapi/analyze_stock. ashx? stock=" + s. Stock ; Http. Web. Request request = Http. Web. Request. Create(target. Url) as Http. Web. Request; request. Method = "GET"; request. Content. Type = "application/x-www-form-urlencoded"; request. Timeout = 30000 ; string result = ""; using (Http. Web. Response response = request. Get. Response() as Http. Web. Response) { using (Stream. Reader sr = new Stream. Reader(response. Get. Response. Stream())) { result = sr. Read. To. End(); } } string s. Stock. Info = result. Split(': ')[1]. Split('}')[0]. Replace(""", ""); string[] a. Stock. Info = s. Stock. Info. Split(' ,'); string s. Stock. Name = a. Stock. Info[0]. Trim (); //股票名稱 string s. Open. Price = a. Stock. Info[1]. Split (‘為’)[1]; //開盤價 string s. Now. Price = a. Stock. Info[2]. Split (‘為’)[1]; //現價 紅字部分為要塞進資料庫的資料

IIS 控制台→程式集→開啟或關閉Windows功能→Internet Information Services

IIS 控制台→程式集→開啟或關閉Windows功能→Internet Information Services

The End

The End