Skip to content

Commit

Permalink
add remote tunnel to vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzaizai2k committed Dec 1, 2023
1 parent 20d6ee5 commit 3bd3e96
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ config/config.py
/data
/venv
*png
*.gz
code
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
3. [Warning Price](#warning-price)
3. [Database](#database)
3. [Example Uses](#example-uses)
3. [Open VScode tunnel](#open-vscode-tunnel)
3. [To-Do List](#to-do-list)

## Introduction
Expand All @@ -29,6 +30,7 @@ Welcome to the Mrzaizai2k Stock Assistant bot! This bot is designed to assist yo
13. `/winlossanalyze`: Analyze my Win/Loss trading for the last 6 months (FPTS data)
14. `/watchlist`: See/change your watch list
15. `/winlossanalyze`: Analyze my Win/Loss trading for the last 6 months (FPTS data)
15. `/remote`: Open remote tunnel to vscode on my latop

## How to Use
1. Start a command with a forward slash ("/") followed by the desired command.
Expand Down Expand Up @@ -122,6 +124,17 @@ Before running the Mrzaizai2k Stock Assistant Bot, follow these steps to set up
Explore practical implementations and demonstrations of the chatbot's functions in the `notebook` folder. These examples showcase real-world scenarios, illustrating how the chatbot can be effectively utilized for stock market monitoring.

## Open VScode tunnel
As to this [link](https://code.visualstudio.com/docs/remote/tunnels#:~:text=In%20the%20VS%20Code%20Account,prompted%20to%20log%20into%20GitHub), you need to first set up the tunnel in your code

curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz

tar -xf vscode_cli.tar.gz

Then use this command

./code tunnel

## To-Do List

- [ ] **Stock Prediction with TFT Model**
Expand Down
126 changes: 126 additions & 0 deletions notebook/remote_tunnel.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/root/code_Bao/stock_price_4_fun/notebook\n"
]
}
],
"source": [
"import os\n",
"try:\n",
" print(file_path)\n",
"except:\n",
" file_path = os.path.abspath('')\n",
" os.chdir(os.path.dirname(file_path))\n",
" print(file_path)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import subprocess"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"*\n",
"* Visual Studio Code Server\n",
"*\n",
"* By using the software, you agree to\n",
"* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and\n",
"* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).\n",
"*\n",
"\n",
"Open this link in your browser https://vscode.dev/tunnel/bao_msi/root/code_Bao/stock_price_4_fun\n",
"\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb Cell 3\u001b[0m line \u001b[0;36m8\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3'>4</a>\u001b[0m command \u001b[39m=\u001b[39m [\u001b[39m'\u001b[39m\u001b[39m./code\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mtunnel\u001b[39m\u001b[39m'\u001b[39m]\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5'>6</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=6'>7</a>\u001b[0m \u001b[39m# Run the command\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=7'>8</a>\u001b[0m result \u001b[39m=\u001b[39m subprocess\u001b[39m.\u001b[39;49mrun(command, check\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, text\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=8'>9</a>\u001b[0m \u001b[39m# tunnel_output = result.stdout.strip()\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9'>10</a>\u001b[0m \u001b[39m# print ('tunnel_output', tunnel_output)\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39m# # Parse the output to extract the vscode.dev URL\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=16'>17</a>\u001b[0m \n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=17'>18</a>\u001b[0m \u001b[39m# Display success message\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/root/code_Bao/stock_price_4_fun/notebook/remote_tunnel.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=18'>19</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mCommand executed successfully.\u001b[39m\u001b[39m\"\u001b[39m)\n",
"File \u001b[0;32m/usr/lib/python3.10/subprocess.py:505\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(input, capture_output, timeout, check, *popenargs, **kwargs)\u001b[0m\n\u001b[1;32m 503\u001b[0m \u001b[39mwith\u001b[39;00m Popen(\u001b[39m*\u001b[39mpopenargs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39mas\u001b[39;00m process:\n\u001b[1;32m 504\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 505\u001b[0m stdout, stderr \u001b[39m=\u001b[39m process\u001b[39m.\u001b[39;49mcommunicate(\u001b[39minput\u001b[39;49m, timeout\u001b[39m=\u001b[39;49mtimeout)\n\u001b[1;32m 506\u001b[0m \u001b[39mexcept\u001b[39;00m TimeoutExpired \u001b[39mas\u001b[39;00m exc:\n\u001b[1;32m 507\u001b[0m process\u001b[39m.\u001b[39mkill()\n",
"File \u001b[0;32m/usr/lib/python3.10/subprocess.py:1146\u001b[0m, in \u001b[0;36mPopen.communicate\u001b[0;34m(self, input, timeout)\u001b[0m\n\u001b[1;32m 1144\u001b[0m stderr \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstderr\u001b[39m.\u001b[39mread()\n\u001b[1;32m 1145\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mstderr\u001b[39m.\u001b[39mclose()\n\u001b[0;32m-> 1146\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mwait()\n\u001b[1;32m 1147\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 1148\u001b[0m \u001b[39mif\u001b[39;00m timeout \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n",
"File \u001b[0;32m/usr/lib/python3.10/subprocess.py:1209\u001b[0m, in \u001b[0;36mPopen.wait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 1207\u001b[0m endtime \u001b[39m=\u001b[39m _time() \u001b[39m+\u001b[39m timeout\n\u001b[1;32m 1208\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 1209\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_wait(timeout\u001b[39m=\u001b[39;49mtimeout)\n\u001b[1;32m 1210\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyboardInterrupt\u001b[39;00m:\n\u001b[1;32m 1211\u001b[0m \u001b[39m# https://bugs.python.org/issue25942\u001b[39;00m\n\u001b[1;32m 1212\u001b[0m \u001b[39m# The first keyboard interrupt waits briefly for the child to\u001b[39;00m\n\u001b[1;32m 1213\u001b[0m \u001b[39m# exit under the common assumption that it also received the ^C\u001b[39;00m\n\u001b[1;32m 1214\u001b[0m \u001b[39m# generated SIGINT and will exit rapidly.\u001b[39;00m\n\u001b[1;32m 1215\u001b[0m \u001b[39mif\u001b[39;00m timeout \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n",
"File \u001b[0;32m/usr/lib/python3.10/subprocess.py:1959\u001b[0m, in \u001b[0;36mPopen._wait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 1957\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mreturncode \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 1958\u001b[0m \u001b[39mbreak\u001b[39;00m \u001b[39m# Another thread waited.\u001b[39;00m\n\u001b[0;32m-> 1959\u001b[0m (pid, sts) \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_try_wait(\u001b[39m0\u001b[39;49m)\n\u001b[1;32m 1960\u001b[0m \u001b[39m# Check the pid and loop as waitpid has been known to\u001b[39;00m\n\u001b[1;32m 1961\u001b[0m \u001b[39m# return 0 even without WNOHANG in odd situations.\u001b[39;00m\n\u001b[1;32m 1962\u001b[0m \u001b[39m# http://bugs.python.org/issue14396.\u001b[39;00m\n\u001b[1;32m 1963\u001b[0m \u001b[39mif\u001b[39;00m pid \u001b[39m==\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpid:\n",
"File \u001b[0;32m/usr/lib/python3.10/subprocess.py:1917\u001b[0m, in \u001b[0;36mPopen._try_wait\u001b[0;34m(self, wait_flags)\u001b[0m\n\u001b[1;32m 1915\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"All callers to this function MUST hold self._waitpid_lock.\"\"\"\u001b[39;00m\n\u001b[1;32m 1916\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 1917\u001b[0m (pid, sts) \u001b[39m=\u001b[39m os\u001b[39m.\u001b[39;49mwaitpid(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mpid, wait_flags)\n\u001b[1;32m 1918\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mChildProcessError\u001b[39;00m:\n\u001b[1;32m 1919\u001b[0m \u001b[39m# This happens if SIGCLD is set to be ignored or waiting\u001b[39;00m\n\u001b[1;32m 1920\u001b[0m \u001b[39m# for child processes has otherwise been disabled for our\u001b[39;00m\n\u001b[1;32m 1921\u001b[0m \u001b[39m# process. This child is dead, we can't get the status.\u001b[39;00m\n\u001b[1;32m 1922\u001b[0m pid \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpid\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"import subprocess\n",
"\n",
"# Define the command\n",
"command = ['./code', 'tunnel']\n",
"\n",
"try:\n",
" # Run the command\n",
" result = subprocess.run(command, check=True, text=True)\n",
" # tunnel_output = result.stdout.strip()\n",
" # print ('tunnel_output', tunnel_output)\n",
" # # Parse the output to extract the vscode.dev URL\n",
" # url_start = tunnel_output.find('https://vscode.dev/tunnel/')\n",
" # print ('url_start', url_start)\n",
"\n",
" # vscode_url = tunnel_output[url_start:]\n",
" # print ('vscode_url', vscode_url)\n",
"\n",
" # Display success message\n",
" print(\"Command executed successfully.\")\n",
"\n",
" # Display command output (if any)\n",
" if result.stdout:\n",
" print(\"Command output:\")\n",
" print(result.stdout)\n",
"\n",
"except subprocess.CalledProcessError as e:\n",
" # Handle errors\n",
" print(f\"Error: {e}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
22 changes: 17 additions & 5 deletions src/stock_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import os
import yaml
import schedule
import threading
from threading import Thread
from time import sleep
import subprocess

import telebot
from telebot import types
Expand Down Expand Up @@ -50,6 +52,7 @@ def help(message):
bot.send_message(message.chat.id, "\n/watchlist: See/change watch list")
bot.send_message(message.chat.id, "\n/winlossanalyze: Analyze my win loss trading for the last 6 months (FPTS data)")
bot.send_message(message.chat.id, "\n/buysellanalyze: Picture of my Buy sell for a stock (FPTS data)")
bot.send_message(message.chat.id, "\n/remote: Open remote tunnel to vscode on my latop")


@bot.message_handler(commands=['rate', 'risk', 'pbt','mulpattern', 'pattern','snr','buysellanalyze'])
Expand Down Expand Up @@ -384,18 +387,27 @@ def process_remove_stock(message):
bot.send_message(message.chat.id, f"{symbol} not found in your watchlist.")


# Define the function to handle all other messages
@bot.message_handler(func=lambda message: True)
def echo(message):
response_message = "Apologies, I didn't understand that command. 😕\nPlease type /help to see the list of available commands."
bot.send_message(message.chat.id, response_message)
def run_vscode_tunnel(message):
command = ['./code', 'tunnel']
bot.reply_to(message, f"VS Code remote tunnel opened!: https://vscode.dev/tunnel/bao_msi/root/code_Bao/stock_price_4_fun")
result = subprocess.run(command, check=True, text=True)

@bot.message_handler(commands=['remote'])
def open_vscode_tunnel(message):
bot.reply_to(message, f"VS Code remote tunnel Opening...")
Thread(target=run_vscode_tunnel, args=(message,)).start()


def schedule_checker():
while True:
schedule.run_pending()
sleep(1)

# Define the function to handle all other messages
@bot.message_handler(func=lambda message: True)
def echo(message):
response_message = "Apologies, I didn't understand that command. 😕\nPlease type /help to see the list of available commands."
bot.send_message(message.chat.id, response_message)

def main():
data_config_path = 'config/config.yaml'
Expand Down

0 comments on commit 3bd3e96

Please sign in to comment.