diff --git a/.gitignore b/.gitignore
index cf34c89..12a557b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
*__pychache__
credentials
*pyc
+.env
+.*.swp
+tmp/
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..cba4a4b
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,25 @@
+# Changelog
+> here you can see every change between versions
+
+## v0.4
+### Fixed
+ - python3.4 had problems with singal.signal()
+ - manage project if there is no arguments
+
+## v0.3
+### Added
+ - Handle Ctrl-c in checker
+ - `makefile` with `install` and `uninstall`
+ - `EOL` with a goodbye message
+
+## v0.2
+### Added
+ - `.env` file support, It use `EMAIL`, `PASSWORD`, `API`, `DEBUG` variables
+ - `VERSION`, `PATH_CRED` variables
+
+### Fix
+ - Set installation confirmation problem with ['Y'/'N']
+ - checker.py with pycodestyle
+ - move `hbnb_creds`, the `/tmp` folder delete the credentials
+
+
diff --git a/README.md b/README.md
index 42b6816..231723b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,107 @@
-# ⚡ CLI_Checker ⚡
-A Holberton School checker tool to avoid using your browser to check manaully every task of your current project.
+# ⚡ CLI_Checker (vTavo) ⚡
+ > A Holberton School checker tool to avoid using your browser to check manaully every task of your current project.
+ > This is a fork of the original project by Diego Lopez. Please check his [page][CLI_Diego]
+## Prerquisites
+You need the [tools][api_link] section available in the intranet. You can check
+if you have this icon in the left menu:
+
+
+
+
+
+## How to install
+
+Run the instalation script
+```console
+$ bash <(curl -sL https://github.com/Athesto/CLI_Checker/raw/main/install.sh)
+$ checker
+```
+the program are going to ask for:
+ - your holberton's __email__ (xxxx@holbertonshcool.com)
+ - your __API__ key ([link][api_link])
+ - it's in the __Intranet > Tools > Holberton's Intranet API key__
+ - it's an HEX string of 32 chars ex. `123abc123abcdef99001122cdef12351`
+ - your intranet's __password__ (it will be hidden so don't worry if you don't see the chars)
+
+## How to use
+just run cecker in your terminal ant the checker terminal will start
+
+```console
+$ checker
+CLI-Checker ⚡
+```
+Now that you are in the console, you has to select the project with `project `.
+The project's number is the last number of the url
+
+#### Example of use
+Suppose that you want to check the project __0x00. C - Hello, World__
+The url is `https://intranet.hbtn.io/projects/212`
+So, the project's number is __212__
+```console
+CLI-@Checker ⚡$ project 212
+0 - Preprocessor
+1 - Compiler
+2 - Assembler
+3 - Name
+4 - Hello, puts
+5 - Hello, printf
+6 - Size is not grandeur, and territory does not make a nation
+7 - What happens when you type gcc main.c
+8 - Intel
+9 - UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity
+
+ ┌─ You may now run:
+ │
+ └─┬─ check
+ ├ To check a specific task.
+ │
+ ├─ check Not implemented yet🤕, Sorry.
+ ├ To check all tasks of current project.
+ └─┐
+ ├─ To check only task 2 you would run
+ │
+ └─ Example: check 2
+
+CLI-@Checker ⚡$ check 1
+Task 1 Compiler
+Checking your code... 🎉
+🔥 Check 0: Approved 🏆
+⚡ Check 1: Approved 🔥
+🤩 Check 2: Approved 🎊
+🥂 Check 3: Approved 🔥
+```
+
+### Available commands
+ - help: show help. `available` is misspelled
+ - EOF: (Ctrl-D) finish the console
+ - quit: finish the console (same as EOF)
+ - project: select project
+ - check: slect task
+
+### How to uninstall
+To uninstall you only need to delete these files
+ - `/opt/checker`
+ - `/usr/local/bin/checker`
+ - credentials in `~/.config/hbn`
+```console
+$ sudo rm -rf /opt/checker/
+$ sudo rm /usr/local/bin/checker
+$ rm -rf ~/.config/hbn
+```
## Contributors
-- Diego Lopez
-- Wiston Venera
-- Leonardo Valencia
+- [Diego Lopez][@DiegoCol93]
+- [Wiston Venera][@wsvem]
+- [Leonardo Valencia][@4ions]
+- [Gustavo Mejía][@Athesto]
+
+
+[api_link]: https://intranet.hbtn.io/dashboards/my_tools
+[@Athesto]: https://github.com/Athesto
+[@wsvem]: https://github.com/wisvem
+[@4ions]: https://github.com/4ions
+[@DiegoCol93]: https://github.com/DiegoCol93
+[CLI_Diego]: https://github.com/DiegoCol93/CLI_Checker/
+[tool_icon2]: https://github.com/Athesto/CLI_Checker/raw/main/assets/tool_icon2.png
+[tool_icon3]: /assets/tool_icon2.png
+
diff --git a/assets/tool_icon.png b/assets/tool_icon.png
new file mode 100644
index 0000000..71b5e98
Binary files /dev/null and b/assets/tool_icon.png differ
diff --git a/assets/tool_icon2.png b/assets/tool_icon2.png
new file mode 100644
index 0000000..ebe6614
Binary files /dev/null and b/assets/tool_icon2.png differ
diff --git a/checker.py b/checker.py
index fa08d56..6567c8e 100755
--- a/checker.py
+++ b/checker.py
@@ -5,22 +5,44 @@
from modules.get_project import get_tasks
from modules.get_auth import get_auth
-from os import path, get_terminal_size, getenv
+from os import path, get_terminal_size, getenv, makedirs
from getpass import getpass
from time import sleep
from cmd import Cmd
import json
+import signal # manage Ctrl-C
+# GLOBAL VARIABLES
+PATH_CREDS = path.expanduser('~/.config/hbn/hbnb_creds')
+PATH_TOKEN = '/tmp/.hbnb_auth_token'
+VERSION = 'v0.4 (tavo)'
+REPO = "https://github.com/Athesto/CLI_Checker"
# Color format for text printing.
y = '\033[38;5;220m' # Yellow.
g = '\033[92m' # Green.
-r = '\033[91m' # Red
-rs= '\033[m' # Reset.
+r = '\033[91m' # Red
+rs = '\033[m' # Reset.
# Get the size of the tty.
size = get_terminal_size()
columns = size.columns
+# debug credentials: This information should be in the .env file as
+# EMAIL=
+# ENABLE=True/False
+# API=
+# PASSWORD=
+debug = bool(getenv('DEBUG', False))
+debug_cred = {
+ "enable": debug,
+ "email": getenv('EMAIL'),
+ "api": getenv('API'),
+ "password": getenv('PASSWORD')
+}
+
+if (debug is True):
+ print(debug_cred)
+
class CLI_Checker(Cmd):
""" Class for controling the main loop of the Checker's Console. """
@@ -35,100 +57,113 @@ class CLI_Checker(Cmd):
# Help custom instance variables.
doc_header = "🤔 Currently availbale commands are: 🤔"
ruler = y + "─" + rs
+ original_handler_ctrl_c = signal.getsignal(signal.SIGINT)
+
+ def __init__(self):
+ super().__init__()
+ signal.signal(signal.SIGINT, self._ctrl_c_ignored)
+
+ def _ctrl_c_ignored(self, signal, frame):
+ '''Ignore SIGINT signal'''
+ print('^C')
+ print(self.prompt, end='', flush=True)
# Overrides the preloop class method. - - - - - - - - - - - - - - - - - - |
def preloop(self):
""" Method that runs before the main loop of the console. """
- if path.exists('/tmp/.hbnb_creds'):
- with open('/tmp/.hbnb_creds', 'r') as f:
+ if path.exists(PATH_CREDS):
+ with open(PATH_CREDS, 'r') as f:
creds = json.load(f)
email = creds['email']
api = creds['api']
password = creds['password']
get_auth(email, api, password)
else:
- if path.exists('/tmp/.hbnb_auth_token'):
+ if path.exists(PATH_TOKEN):
return
else:
+ print('Credentials not found')
print('\033[2J', end='')
+
self.start_up()
# 1st time startup method.- - - - - - - - - - - - - - - - - - - - - - - -|
def start_up(self):
""" Start-up method for getting and storing the user's credentials. """
# Strings for 1st time welcome pre-message.
- welcome_l0 = "Hi"
- welcome_l1 = "This is the"
- welcome_l2 = "CLI-Checker v0.01"
- welcome_l3 = "We hope you enjoy"
- welcome_l4 = "Please"
- welcome_l5 = "Report any issues"
- welcome_l6 = "At:"
- welcome_l7 = "https://github.com/DiegoCol93/CLI_Checker"
- welcome_l8 = "or Follow us in Twitter:"
- welcome_l9 = "https://twitter.com/LopezDfelo93"
- welcome_l10 = "https://twitter.com/wisvem"
- welcome_l11 = "https://twitter.com/leovalsan_dev"
-
- # Calculate the space around each line's welcome message.
- welcome_s0 = ' ' * ((columns // 2) - 1 - len(welcome_l0) // 2)
- welcome_s1 = ' ' * ((columns // 2) - 1 - len(welcome_l1) // 2)
- welcome_s2 = ' ' * ((columns // 2) - 1 - len(welcome_l2) // 2)
- welcome_s3 = ' ' * ((columns // 2) - 1 - len(welcome_l3) // 2)
- welcome_s4 = ' ' * ((columns // 2) - 1 - len(welcome_l4) // 2)
- welcome_s5 = ' ' * ((columns // 2) - 1 - len(welcome_l5) // 2)
- welcome_s6 = ' ' * ((columns // 2) - 1 - len(welcome_l6) // 2)
- welcome_s7 = ' ' * ((columns // 2) - 1 - len(welcome_l7) // 2)
- welcome_s8 = ' ' * ((columns // 2) - 1 - len(welcome_l8) // 2)
- welcome_s9 = ' ' * ((columns // 2) - 1 - len(welcome_l9) // 2)
- welcome_s10 = ' ' * ((columns // 2) - 1 - len(welcome_l10) // 2)
- welcome_s11 = ' ' * ((columns // 2) - 1 - len(welcome_l11) // 2)
-
- # Add color for the line 2 after spaces calculation above.
- welcome_l2 = "CLI-Checker" + g + " v0.01" + rs
-
- # Start of printing animation...
- # \033[2;0f resets the cursor to line 2 column 0 of the terminal.
- print("\033[5;0f", end='')
- print("\033[2;0f", end='')
- print(welcome_s0 + welcome_l0 + welcome_s0)
- sleep(2)
+ if (debug is False):
+ welcome_l0 = "Hi"
+ welcome_l1 = "This is the"
+ welcome_l2 = "CLI-Checker {}".format(VERSION)
+ welcome_l3 = "We hope you enjoy"
+ welcome_l4 = "Please"
+ welcome_l5 = "Report any issues"
+ welcome_l6 = "At:"
+ welcome_l7 = REPO
+ welcome_l8 = "Follow us in Twitter:"
+ welcome_l9 = "https://twitter.com/LopezDfelo93"
+ welcome_l10 = "https://twitter.com/wisvem"
+ welcome_l11 = "https://twitter.com/leovalsan_dev"
+
+ # Calculate the space around each line's welcome message.
+ welcome_s0 = ' ' * ((columns // 2) - 1 - len(welcome_l0) // 2)
+ welcome_s1 = ' ' * ((columns // 2) - 1 - len(welcome_l1) // 2)
+ welcome_s2 = ' ' * ((columns // 2) - 1 - len(welcome_l2) // 2)
+ welcome_s3 = ' ' * ((columns // 2) - 1 - len(welcome_l3) // 2)
+ welcome_s4 = ' ' * ((columns // 2) - 1 - len(welcome_l4) // 2)
+ welcome_s5 = ' ' * ((columns // 2) - 1 - len(welcome_l5) // 2)
+ welcome_s6 = ' ' * ((columns // 2) - 1 - len(welcome_l6) // 2)
+ welcome_s7 = ' ' * ((columns // 2) - 1 - len(welcome_l7) // 2)
+ welcome_s8 = ' ' * ((columns // 2) - 1 - len(welcome_l8) // 2)
+ welcome_s9 = ' ' * ((columns // 2) - 1 - len(welcome_l9) // 2)
+ welcome_s10 = ' ' * ((columns // 2) - 1 - len(welcome_l10) // 2)
+ welcome_s11 = ' ' * ((columns // 2) - 1 - len(welcome_l11) // 2)
+
+ # Add color for the line 2 after spaces calculation above.
+ welcome_l2 = "CLI-Checker" + g + " " + VERSION + rs
+
+ # Start of printing animation...
+ # \033[2;0f resets the cursor to line 2 column 0 of the terminal.
+ print("\033[5;0f", end='')
+ print("\033[2;0f", end='')
+ print(welcome_s0 + welcome_l0 + welcome_s0)
+ sleep(2)
- print(welcome_s1 + welcome_l1 + welcome_s1)
- sleep(1.5)
+ print(welcome_s1 + welcome_l1 + welcome_s1)
+ sleep(1.5)
- print(welcome_s2 + welcome_l2 + welcome_s2)
- sleep(1.5)
+ print(welcome_s2 + welcome_l2 + welcome_s2)
+ sleep(1.5)
- print("\033[2;0f", end='')
- print(welcome_s3 + welcome_l3 + welcome_s3)
- sleep(1.5)
+ print("\033[2;0f", end='')
+ print(welcome_s3 + welcome_l3 + welcome_s3)
+ sleep(1.5)
- print(welcome_s4 + welcome_l4 + welcome_s4)
- sleep(1.5)
+ print(welcome_s4 + welcome_l4 + welcome_s4)
+ sleep(1.5)
- print(welcome_s5 + welcome_l5 + welcome_s5)
- sleep(1.5)
+ print(welcome_s5 + welcome_l5 + welcome_s5)
+ sleep(1.5)
- print("\033[2;0f", end='')
- print(welcome_s6 + welcome_l6 + welcome_s6)
- sleep(1.5)
+ print("\033[2;0f", end='')
+ print(welcome_s6 + welcome_l6 + welcome_s6)
+ sleep(1.5)
- print(welcome_s7 + welcome_l7 + welcome_s7)
- sleep(1.5)
+ print(welcome_s7 + welcome_l7 + welcome_s7)
+ sleep(1.5)
- print(welcome_s8 + welcome_l8 + welcome_s8)
- sleep(1.5)
+ print(welcome_s8 + welcome_l8 + welcome_s8)
+ sleep(1.5)
- print("\033[2;0f", end='')
- print(welcome_s9 + welcome_l9 + welcome_s9)
- sleep(1.5)
+ print("\033[2;0f", end='')
+ print(welcome_s9 + welcome_l9 + welcome_s9)
+ sleep(1.5)
- print(welcome_s10 + welcome_l10 + welcome_s10)
- sleep(1.5)
+ print(welcome_s10 + welcome_l10 + welcome_s10)
+ sleep(1.5)
- print(welcome_s11 + welcome_l11 + welcome_s11)
- sleep(1.5)
+ print(welcome_s11 + welcome_l11 + welcome_s11)
+ sleep(1.5)
# Get user credentials with input box.- - - - - - - - - - - - - - - - |
print("\033[5;0f", end='')
@@ -137,6 +172,8 @@ def start_up(self):
print('└' + '─' * (columns - 2) + '┘') # Variable, somehow...
print("\033[6;3f", end='')
email = str(input("Please enter your holberton e-mail: "))
+ if (debug is True):
+ email = debug_cred['email']
print("\033[5;0f", end='')
print('┌' + '─' * (columns - 2) + '┐')
@@ -144,19 +181,17 @@ def start_up(self):
print('└' + '─' * (columns - 2) + '┘')
print("\033[6;3f", end='')
api = str(input("Please enter your API key: "))
+ if (debug is True):
+ api = debug_cred['api']
print("\033[5;0f", end='')
print('┌' + '─' * (columns - 2) + '┐')
print('│' + ' ' * (columns - 2) + '│')
print('└' + '─' * (columns - 2) + '┘')
print("\033[6;3f", end='')
- if getenv('PSS'):
- print('PSS environ variable was found...')
- password = getenv('PSS')
- else:
- password = getpass("\033[6;3fPlease enter your password: ")
-
-
+ password = getpass("\033[6;3fPlease enter your password: ")
+ if (debug is True):
+ password = debug_cred['password']
# Load custom mock loading Bar... - - - - - - - - - - - - - - - - - - |
i = 0
@@ -180,7 +215,7 @@ def start_up(self):
print('\033[92m', end='')
print("\033[5;0f", end='')
print('┌' + '─' * (columns - 2) + '┐')
- print('│' + success_space + success + success_space, end = '│')
+ print('│' + success_space + success + success_space, end='│')
print('└' + '─' * (columns - 2) + '┘')
print('\033[m', end='')
print("\033[6;3f", end='')
@@ -196,7 +231,7 @@ def start_up(self):
print('└' + '─' * (columns - 2) + '┘')
print('\033[m', end='')
print("\033[6;3f", end='')
- answer = str(input(question))
+ answer = str(input(question)).lower()
while answer not in self.yes_no_list:
print("\033[5;0f", end='')
print('\033[92m', end='')
@@ -207,10 +242,14 @@ def start_up(self):
print("\033[6;3f", end='')
answer = str(input("Please answer Yes or No: "))
- if answer.lower() in ['yes', 'y']:
- with open('/tmp/.hbnb_creds', 'w+') as f:
- cred = 'Your Credentials have been stored in ' \
- '/tmp/.hbnb_creds'
+ if answer in ['yes', 'y']:
+ try:
+ makedirs(path.dirname(PATH_CREDS))
+ except FileExistsError as f:
+ pass
+ with open(PATH_CREDS, 'w+') as f:
+ cred = 'Your Credentials have been stored in {}'
+ cred.format(PATH_CREDS)
json.dump({'email': email, 'api': api,
'password': password, 'token': ""}, f)
print("\033[5;0f", end='')
@@ -222,7 +261,7 @@ def start_up(self):
print("\033[6;{}f".format((columns - len(cred)) // 2),
end='')
cred = 'Your Credentials have been stored in '
- print(cred + g + '/tmp/.hbnb_creds' + rs)
+ print(cred + g + " " + PATH_CREDS + " " + rs)
sleep(2)
print('')
@@ -244,23 +283,23 @@ def start_up(self):
# Project command - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
def do_project(self, arg):
"""\n""" \
- """ ┌\033[92m─\033[m Fetches and updates the current project.\n""" \
- """ │\n""" \
- """ └─┬\033[92m─\033[m Usage:\n""" \
- """ │\n""" \
- """ ├──\033[92m─\033[m project <\033[92mnum\033[m>\n""" \
- """ │\n""" \
- """ ├\033[92m─\033[m The \033[92mnum\033[m variable represents """ \
- """the number from\n""" \
- """ │ the project's url in your current Holberton proje""" \
- """ct.\n""" \
- """ │\n""" \
- """ └─┬\033[92m─\033[m Example:\n""" \
- """ │\n""" \
- """ ├\033[92m─\033[m From: https://intranet.hbtn.io/projects""" \
- """/\033[92m212\033[m\n""" \
- """ │\n""" \
- """ └\033[92m─\033[m Run: project \033[92m212\033[m\n""" \
+ """ ┌\033[92m─\033[m Fetches and updates the current project.\n""" \
+ """ │\n""" \
+ """ └─┬\033[92m─\033[m Usage:\n""" \
+ """ │\n""" \
+ """ ├──\033[92m─\033[m project <\033[92mnum\033[m>\n""" \
+ """ │\n""" \
+ """ ├\033[92m─\033[m The \033[92mnum\033[m variable represents """ \
+ """the number from\n""" \
+ """ │ the project's url in your current Holberton proje""" \
+ """ct.\n""" \
+ """ │\n""" \
+ """ └─┬\033[92m─\033[m Example:\n""" \
+ """ │\n""" \
+ """ ├\033[92m─\033[m From: https://intranet.hbtn.io/projects""" \
+ """/\033[92m212\033[m\n""" \
+ """ │\n""" \
+ """ └\033[92m─\033[m Run: project \033[92m212\033[m\n""" \
self.task_dict = get_tasks(arg)
@@ -322,11 +361,18 @@ def do_check(self, arg):
print('There is no task # {}'.format(arg))
return
- correction_id = request_correction(self.task_dict[arg][1])
- show_result(correction_id, self.task_dict, arg)
+ try:
+ signal.signal(signal.SIGINT, self.original_handler_ctrl_c)
+ correction_id = request_correction(self.task_dict[arg][1])
+ show_result(correction_id, self.task_dict, arg)
+ except:
+ print("\n\nstop")
+ finally:
+ signal.signal(signal.SIGINT, self._ctrl_c_ignored)
def do_EOF(self, arg):
- """ Exits console when receiving an EOF. """
+ """ Exits console when receiving an EOF (Ctrl-D)"""
+ print("goodbye")
return True
def emptyline(self):
@@ -337,18 +383,22 @@ def do_quit(self, arg):
""" Quit command to exit the console. """
return True
+
if __name__ == '__main__':
from os import get_terminal_size
- space_around = ' ' * ((columns - len('┌───────────────────────────┐')) // 2)
+ space_around = ' ' * \
+ ((columns - len('┌───────────────────────────┐')) // 2)
s = space_around
CLI_Checker().cmdloop(
s + '┌───────────────────────────┐\n' +
- s + '│ CLI-Checker ' + g + 'v0.01' + rs + ' │\n' +
+ s + '│ CLI-Checker │\n' +
+ s + '│ ' + g + VERSION + rs + ' │\n' +
s + '│ by: │\n' +
s + '│ 🔥' + y + ' Diego Lopez ' + rs + '🔥 │\n' +
s + '│ 🔥' + y + ' Wiston Venera ' + rs + '🔥 │\n' +
s + '│ 🔥' + y + ' Leonardo Valencia ' + rs + '🔥 │\n' +
+ s + '│ 🔥' + y + ' Gustavo Mejia ' + rs + '🔥 │\n' +
s + '└───────────────────────────┘\n'
'Please run help to see available commands..')
diff --git a/install.sh b/install.sh
index b94e106..7716ad3 100755
--- a/install.sh
+++ b/install.sh
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
+REPO="https://github.com/Athesto/CLI_Checker.git"
+BRANCH=${BRANCH-"main"}
cols=$(tput cols) # ───────────── Get the width of the terminal.
cols=$(($cols - 3)) # ─────────── Substract 3 to prevent overflow.
@@ -56,7 +58,7 @@ while [ $installed != 1 ]; do
echo -en "\033[${size}C"
# 2. Clone repository into installation directory.
- if sudo git -C /opt/checker clone https://github.com/DiegoCol93/CLI_Checker.git 2> /dev/null; then
+ if sudo git -C /opt/checker clone -b ${BRANCH} ${REPO} 2> /dev/null; then
echo -ne '\033[92m'
printf '█%.0s' $(seq 0 $size)
echo -ne '\033[m'
@@ -115,7 +117,7 @@ while [ $installed != 1 ]; do
(( installed++ ))
echo ""
- echo -e "CLI_Checker \033[92mv0.01\033[m has been installed \033[92msuccesfully\033[m."
+ echo -e "CLI_Checker has been installed \033[92msuccesfully\033[m."
echo -e "You may now run:\n"
echo -e "\t\033[92mchecker\033[m\n"
echo -e "In order to start the checker console."
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..6a4f39a
--- /dev/null
+++ b/makefile
@@ -0,0 +1,8 @@
+SHELL:=/bin/bash
+
+install:
+ bash <(curl -sL https://github.com/Athesto/CLI_Checker/raw/main/install.sh)
+
+uninstall:
+ sudo rm -rf /opt/checker/
+ sudo rm /usr/local/bin/checker
diff --git a/modules/get_project.py b/modules/get_project.py
index 2572941..0c70b4e 100755
--- a/modules/get_project.py
+++ b/modules/get_project.py
@@ -4,49 +4,64 @@
from os import environ, path
from sys import argv as av
from requests import get
-from json import dump
+from json import dump, load
+
+PATH_CURRENT_PROJECT = '/tmp/.hbnb_current_project'
+
def get_tasks(project_number):
""" Prints all of the ids of the tasks in the given project. """
- if path.exists('/tmp/.hbnb_auth_token') is None:
- print("No /tmp/.hbnb_auth_token file...")
- return
+ bad_emoji = ['🤢', '🤕', '🤮', '🥵', '🤒', '😵', '🤯', '🥶', '🩹']
- with open('/tmp/.hbnb_auth_token', 'r') as f:
- auth = f.read()
+ if (project_number != ""):
+ if path.exists('/tmp/.hbnb_auth_token') is False:
+ print("No /tmp/.hbnb_auth_token file...")
+ return
- url = "https://intranet.hbtn.io/projects/{}.json?auth_token={}" \
- .format(project_number, auth)
+ with open('/tmp/.hbnb_auth_token', 'r') as f:
+ auth = f.read()
- response = get(url)
+ url = "https://intranet.hbtn.io/projects/{}.json?auth_token={}" \
+ .format(project_number, auth)
- bad_emoji = ['🤢', '🤕', '🤮', '🥵', '🤒', '😵', '🤯', '🥶', '🩹']
+ response = get(url)
- if response.status_code == 200:
- try:
- tasks = response.json()['tasks']
- except:
- print('{} This project is not available for you yet sorry. {}'
- .format(bad_emoji[rand(0,8)], bad_emoji[rand(0,8)]))
+ if response.status_code == 200:
+ try:
+ tasks = response.json()['tasks']
+ except:
+ print('{} This project is not available for you yet sorry. {}'
+ .format(bad_emoji[rand(0, 8)], bad_emoji[rand(0, 8)]))
+ return
+ else:
+ # Error no project found.
+ print('{} The project # \033[91m{}\033[m was \033[91m{}\033[m {}'
+ .format(bad_emoji[rand(0, 8)], project_number,
+ response.json()['error'], bad_emoji[rand(0, 8)]))
return
+
+ number = 0
+ tasks_dict = {}
+ for task in tasks:
+ title = task['title']
+ task_id = task['id']
+ tasks_dict[str(number)] = [title, task_id]
+ number += 1
else:
- # Error no project found.
- print('{} The project # \033[91m{}\033[m was \033[91m{}\033[m {}'
- .format(bad_emoji[rand(0,8)], project_number,
- response.json()['error'], bad_emoji[rand(0,8)]))
- return
-
- number = 0
- tasks_dict = {}
- for task in tasks:
- title = task['title']
- task_id = task['id']
+ if path.exists(PATH_CURRENT_PROJECT) is True:
+ with open(PATH_CURRENT_PROJECT, 'r') as f:
+ tasks_dict = load(f)
+ else:
+ print('{} Project not found'.format(bad_emoji[rand(0, 8)]))
+ return
+
+ for key, value in sorted(tasks_dict.items()):
+ number = key
+ [title, task_id] = value
print('\033[92m{}\033[m - {}'.format(number, title))
- tasks_dict[str(number)] = [title, task_id]
- number += 1
- with open('/tmp/.hbnb_current_project', 'w') as f:
+ with open(PATH_CURRENT_PROJECT, 'w') as f:
dump(tasks_dict, f)
return(tasks_dict)