defupdate_stock_data(self): stock_data = self.get_stock_data() if stock_data: stock_name_mapping = dict(zip(stock_symbols, name)) display_text = "<br>".join([ f"<font color={zhang_color}> {symbol}{stock_name_mapping.get(symbol, symbol)}: {data['current']}{data['percent']}%</font>"if data['percent'] >= 0else f"<font color={die_color}> {symbol}{stock_name_mapping.get(symbol, symbol)}: {data['current']}{data['percent']}%</font>" for symbol, data in stock_data.items() ]) self.label.setText(display_text)
defget_stock_data(self): stock_data = {} for symbol in stock_symbols: url = f"https://stock.xueqiu.com/v5/stock/realtime/quotec.json?symbol={symbol}" try: response = requests.get(url, headers=headers) response.raise_for_status() data = response.json()
ifisinstance(data["data"], list) andlen(data["data"]) > 0: quote_data = data["data"][0] stock_data[symbol] = { "current": quote_data.get("current", None), "percent": quote_data.get("percent", None), } else: print(f"No data found for {symbol}") except requests.exceptions.RequestException as e: print(f"Error fetching data for {symbol}: {e}")