Skip to content

Commit

Permalink
adding helper to setup telegram bot token
Browse files Browse the repository at this point in the history
  • Loading branch information
solderzzc committed Sep 17, 2022
1 parent 7fd2764 commit ede435c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/sharpai_hub/commands/yolov7_reid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, args):
self.log_path = os.path.join(self.runtime_folder,'log.txt')
self.labelstudio_server_url = 'http://localhost:8080'
self.first_run = True
self.telegram_token = None

def check_credential(self):
pass
Expand All @@ -73,11 +74,19 @@ def load_env(self):
# self.labelstudio_server_url = envs['LABEL_STUDIO_URL']
self.labelstudio_project_id = envs['LABEL_STUDIO_PROJECT_ID']
self.labelstudio_token = envs['LABEL_STUDIO_TOKEN']

try:
self.telegram_token = envs['TELEGRAM_TOKEN']
except KeyError:
self.telegram_token = None
def save_environments(self):
with open(self.env_path, "w") as f:
f.write(f"LABEL_STUDIO_URL=http://labelstudio:8080\n")
f.write(f"LABEL_STUDIO_PROJECT_ID={self.labelstudio_project_id}\n")
f.write(f"LABEL_STUDIO_TOKEN={self.labelstudio_token}\n")

if self.telegram_token != None:
f.write(f"TELEGRAM_TOKEN={self.telegram_token}\n")

def helper_to_setup_labelstudio(self):
os.makedirs(self.img_dir, exist_ok=True)
Expand Down Expand Up @@ -111,7 +120,7 @@ def helper_to_setup_labelstudio(self):
webbrowser.open(self.labelstudio_server_url)
except Exception as e:
pass
print('- 4. Please land on Labelstudio UI, Screen Monitor application need Labelstudio token to save screenshots of the entire screen. ALL information will be saved LOCALLY.\n'
print('- 4. Please land on Labelstudio UI http://localhost:8080, Screen Monitor application need Labelstudio token to save screenshots of the entire screen. ALL information will be saved LOCALLY.\n'
' - 1. In the Label Studio UI, click the user icon in the upper right.\n'
' - 2. Click Account & Settings.\n'
' - 3. Copy the access token.')
Expand All @@ -132,6 +141,10 @@ def helper_to_setup_labelstudio(self):
print('Failed to create labelstudio project. Please file a bug: https://github.com/SharpAI/DeepCamera/issues')
exit(-1)
self.labelstudio_project_id = resp['id']

telegram_token = input('- 5. If you want to use Telegram bot to send message to you, please input the token, otherwise, press Enter to skip:')
if telegram_token != '':
self.telegram_token = telegram_token
self.save_environments()
return True

Expand Down

0 comments on commit ede435c

Please sign in to comment.