Spaces:
Runtime error
Runtime error
Commit
•
58a91e1
1
Parent(s):
7e6f93a
Frontend complete
Browse files- frontend/.streamlit/config.toml +7 -0
- frontend/Login.py +1 -1
- frontend/pages/Code.py +50 -25
- frontend/pages/Usage.py +91 -0
- frontend/🏡_Home.py +38 -20
- testing/DBQueries.py +0 -44
- testing/test.py +0 -87
frontend/.streamlit/config.toml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
|
3 |
+
primaryColor="#818cf8"
|
4 |
+
backgroundColor="#FFFFFF"
|
5 |
+
secondaryBackgroundColor="#F0F2F6"
|
6 |
+
textColor="#262730"
|
7 |
+
font="sans serif"
|
frontend/Login.py
CHANGED
@@ -31,7 +31,7 @@ def auth_page():
|
|
31 |
st.session_state["access_token"] = response.json()['access_token']
|
32 |
st.session_state["refresh_token"] = response.json()['refresh_token']
|
33 |
st.success("Logged in successfully")
|
34 |
-
st.
|
35 |
|
36 |
except Exception as e:
|
37 |
st.error(e)
|
|
|
31 |
st.session_state["access_token"] = response.json()['access_token']
|
32 |
st.session_state["refresh_token"] = response.json()['refresh_token']
|
33 |
st.success("Logged in successfully")
|
34 |
+
st.rerun()
|
35 |
|
36 |
except Exception as e:
|
37 |
st.error(e)
|
frontend/pages/Code.py
CHANGED
@@ -10,41 +10,65 @@ st.set_page_config(
|
|
10 |
page_icon="👋",
|
11 |
layout="wide",
|
12 |
initial_sidebar_state="expanded",
|
|
|
13 |
)
|
14 |
|
15 |
-
st.
|
|
|
|
|
16 |
|
17 |
def logout():
|
18 |
del st.session_state["access_token"]
|
19 |
del st.session_state["refresh_token"]
|
20 |
del st.session_state["username"]
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
with st.sidebar:
|
23 |
if 'username' not in st.session_state:
|
24 |
-
st.
|
|
|
25 |
else:
|
26 |
-
|
27 |
-
st.
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
|
43 |
|
44 |
-
with st.expander("
|
45 |
-
|
|
|
46 |
logout()
|
47 |
-
st.
|
48 |
|
49 |
|
50 |
def code_page():
|
@@ -56,19 +80,20 @@ def code_page():
|
|
56 |
|
57 |
headers={"accept":"application/json"}
|
58 |
|
59 |
-
|
|
|
60 |
API_KEY = st.text_input(label="Enter your API key", label_visibility="hidden",placeholder="Enter your API key", type="password")
|
61 |
-
|
62 |
|
63 |
-
code_input = st.text_area("Code Input", height=300)
|
64 |
comment_placeholder = st.empty()
|
65 |
|
66 |
-
if st.button("Generate Documentation"):
|
67 |
if code_input:
|
68 |
headers['Authorization'] = f"Bearer {st.session_state.access_token}"
|
69 |
response = query_post(base_url + '/api/inference', headers=headers, params={'code_block':code_input, 'api_key':API_KEY})
|
70 |
docstr = response.json()["docstr"]
|
71 |
-
comment_placeholder.subheader("Generated
|
72 |
comment_placeholder.markdown(f"<pre><code>{docstr}</code></pre>", unsafe_allow_html=True)
|
73 |
# Scroll to the comment section
|
74 |
comment_placeholder.empty()
|
|
|
10 |
page_icon="👋",
|
11 |
layout="wide",
|
12 |
initial_sidebar_state="expanded",
|
13 |
+
menu_items={"About": "Built by @HemanthSai7 and @MayureshAgashe2107 with Streamlit"},
|
14 |
)
|
15 |
|
16 |
+
st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!] 🚀")
|
17 |
+
|
18 |
+
|
19 |
|
20 |
def logout():
|
21 |
del st.session_state["access_token"]
|
22 |
del st.session_state["refresh_token"]
|
23 |
del st.session_state["username"]
|
24 |
|
25 |
+
def instructions():
|
26 |
+
with st.expander("📝Instructions",expanded=True):
|
27 |
+
st.markdown(
|
28 |
+
"""
|
29 |
+
##### 1. Generate an `API Key` from the sidebar to get started.
|
30 |
+
|
31 |
+
##### 2. Paste the `API Key` in the field provided.
|
32 |
+
|
33 |
+
##### 3. Paste your code function in the input code box.
|
34 |
+
|
35 |
+
##### 4. Click on the `Generate Documentation` 🤖 button to generate the documentation.
|
36 |
+
|
37 |
+
##### 5. The generated documentation will be displayed in the section below.
|
38 |
+
|
39 |
+
"""
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
with st.sidebar:
|
44 |
if 'username' not in st.session_state:
|
45 |
+
with st.expander("🧑Account Details",expanded=True):
|
46 |
+
st.header("Please Login or Signup to continue")
|
47 |
else:
|
48 |
+
|
49 |
+
with st.expander("🔑 TECHDOCS-API-KEY",expanded=True):
|
50 |
+
st.warning("Generating a new API Key will invalidate the previous one from all your projects. Do you wish to continue?")
|
51 |
+
if st.button("Generate API KEY"):
|
52 |
+
with st.spinner("Generating API Key..."):
|
53 |
+
try:
|
54 |
+
base_url = "http://localhost:8000"
|
55 |
+
headers={"accept":"application/json", "Authorization": f"Bearer {st.session_state.access_token}"}
|
56 |
+
response = requests.put(url=base_url + "/auth/regenerate_api_key", headers=headers, data=json.dumps({"username":st.session_state.username}))
|
57 |
+
if (response.status_code!=200):
|
58 |
+
raise Exception("API Key Generation Failed")
|
59 |
+
st.info("Please save the API KEY as it will be shown only once.")
|
60 |
+
st.code(response.json()["api_key"],"bash")
|
61 |
+
st.success("API Key Generated Successfully")
|
62 |
+
except Exception as e:
|
63 |
+
st.error(e)
|
64 |
|
65 |
|
66 |
|
67 |
+
with st.expander("🧑Account Details",expanded=True):
|
68 |
+
st.info(f"Welcome, {st.session_state.username}! 😄")
|
69 |
+
if st.button("Logout 👋"):
|
70 |
logout()
|
71 |
+
st.rerun()
|
72 |
|
73 |
|
74 |
def code_page():
|
|
|
80 |
|
81 |
headers={"accept":"application/json"}
|
82 |
|
83 |
+
instructions()
|
84 |
+
st.warning("Hi there! Paste your TECHDOCS-API-KEY in the field below to get started!\n\n", icon="🚨")
|
85 |
API_KEY = st.text_input(label="Enter your API key", label_visibility="hidden",placeholder="Enter your API key", type="password")
|
86 |
+
|
87 |
|
88 |
+
code_input = st.text_area("Code Input", height=300, help="Paste your code here")
|
89 |
comment_placeholder = st.empty()
|
90 |
|
91 |
+
if st.button("🤖 Generate Documentation"):
|
92 |
if code_input:
|
93 |
headers['Authorization'] = f"Bearer {st.session_state.access_token}"
|
94 |
response = query_post(base_url + '/api/inference', headers=headers, params={'code_block':code_input, 'api_key':API_KEY})
|
95 |
docstr = response.json()["docstr"]
|
96 |
+
comment_placeholder.subheader("Generated Documentation:")
|
97 |
comment_placeholder.markdown(f"<pre><code>{docstr}</code></pre>", unsafe_allow_html=True)
|
98 |
# Scroll to the comment section
|
99 |
comment_placeholder.empty()
|
frontend/pages/Usage.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from Login import auth_page
|
3 |
+
|
4 |
+
st.set_page_config(
|
5 |
+
page_title="Usage",
|
6 |
+
layout="wide",
|
7 |
+
page_icon="📝",
|
8 |
+
initial_sidebar_state="expanded",
|
9 |
+
)
|
10 |
+
|
11 |
+
st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!]🚀")
|
12 |
+
|
13 |
+
def logout():
|
14 |
+
del st.session_state["access_token"]
|
15 |
+
del st.session_state["refresh_token"]
|
16 |
+
del st.session_state["username"]
|
17 |
+
|
18 |
+
with st.sidebar.expander("🧑Account Details",expanded=True):
|
19 |
+
if 'username' not in st.session_state:
|
20 |
+
st.warning("Please Login or Signup to continue")
|
21 |
+
else:
|
22 |
+
st.info(f"Welcome, {st.session_state.username}! 😄")
|
23 |
+
if st.button("Logout 👋"):
|
24 |
+
logout()
|
25 |
+
st.rerun()
|
26 |
+
|
27 |
+
def usage():
|
28 |
+
st.markdown("### :rainbow[How to use Techdocs?]")
|
29 |
+
|
30 |
+
col1,col2 = st.columns(2,gap="small")
|
31 |
+
|
32 |
+
with col1:
|
33 |
+
|
34 |
+
st.image("../assets/image.png",width=300,use_column_width=True)
|
35 |
+
|
36 |
+
st.caption("Boat sailing in the sea")
|
37 |
+
|
38 |
+
with col2:
|
39 |
+
intro_text="""
|
40 |
+
Now that you've arrived at this digital crossroads, you're most likely eager to dive into the world of Techdocs. Great choice! In today's fast-paced tech landscape, having well-structured and easily accessible documentation is like having a treasure map to navigate the vast ocean of code. You are probably wondering how to use Techdocs.
|
41 |
+
"""
|
42 |
+
|
43 |
+
text="""
|
44 |
+
But you might be wondering: "How do I embark on this documentation journey with Techdocs?" Fear not, because we're about to chart a course through the fascinating world of Techdocs, where clarity, efficiency, and ease-of-use are the guiding stars.
|
45 |
+
"""
|
46 |
+
st.write(f'<p style="font-size:20px; color:#9c9d9f ">{intro_text}</p>', unsafe_allow_html=True)
|
47 |
+
st.write(f'<p style="color:#9c9d9f; font-size:20px">{text}</p>', unsafe_allow_html=True)
|
48 |
+
|
49 |
+
st.markdown("### 📝 Using Techdocs via the CLI")
|
50 |
+
|
51 |
+
with st.expander("⚙️ Installation and setup",expanded=True):
|
52 |
+
st.text("1. Create a virtual environment. We recommend using conda but you can python's venv as well:"); st.code("conda create -n techdocs python=3.11","python")
|
53 |
+
st.text("2. Install Techdocs via pip:"); st.code("pip install techdocs","python")
|
54 |
+
st.text("3. CD into your project directory.")
|
55 |
+
st.code("CD <YOUR-PROJECT-DIRECTORY>","bash")
|
56 |
+
st.text("""
|
57 |
+
4. Login into our Techdocs Streamlit app or signup if you don't have an account.
|
58 |
+
|
59 |
+
5. Generate an API Key from the Techdocs Streamlit app and paste it in the command below.
|
60 |
+
""")
|
61 |
+
st.code("techdocs -k <API_KEY> -u <USERNAME> -p <PASSWORD> -d <ROOT-DIRECTORY-OF-THE -PROJECT","bash")
|
62 |
+
st.text("6. Wait for the documentation to be generated. You can view the status of the documentation generation in the CLI.")
|
63 |
+
|
64 |
+
st.divider()
|
65 |
+
st.markdown("### 📝 Using Techdocs via the Streamlit")
|
66 |
+
|
67 |
+
with st.expander("📝Instructions",expanded=True):
|
68 |
+
st.markdown(
|
69 |
+
"""
|
70 |
+
##### 1. Head over to the Code Page.
|
71 |
+
|
72 |
+
##### 2. Generate an `API Key` from the sidebar to get started.
|
73 |
+
|
74 |
+
##### 3. Paste the `API Key` in the field provided.
|
75 |
+
|
76 |
+
##### 4. Paste your code function in the input code box.
|
77 |
+
|
78 |
+
##### 5. Click on the `Generate Documentation`🤖 button to generate the documentation.
|
79 |
+
|
80 |
+
##### 6. The generated documentation will be displayed in the section below.
|
81 |
+
|
82 |
+
"""
|
83 |
+
)
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
if 'access_token' not in st.session_state:
|
88 |
+
st.session_state.runpage = auth_page
|
89 |
+
else:
|
90 |
+
st.session_state.runpage = usage
|
91 |
+
st.session_state.runpage()
|
frontend/🏡_Home.py
CHANGED
@@ -19,21 +19,21 @@ def get_base64_bin_file(bin_file):
|
|
19 |
data = f.read()
|
20 |
return base64.b64encode(data).decode()
|
21 |
|
22 |
-
st.markdown("
|
23 |
|
24 |
def logout():
|
25 |
del st.session_state["access_token"]
|
26 |
del st.session_state["refresh_token"]
|
27 |
del st.session_state["username"]
|
28 |
|
29 |
-
with st.sidebar:
|
30 |
if 'username' not in st.session_state:
|
31 |
-
st.
|
32 |
else:
|
33 |
-
st.
|
34 |
-
if st.button("Logout"):
|
35 |
logout()
|
36 |
-
st.
|
37 |
|
38 |
|
39 |
def home_page():
|
@@ -58,31 +58,49 @@ def home_page():
|
|
58 |
st.markdown(
|
59 |
"""
|
60 |
|
61 |
-
##### Unleash the documentation dynamo that is **Techdocs**! Say goodbye to the documentation drudgery that haunts coders' dreams and embrace the effortless power of AI-driven documentation. With **Techdocs**, harness the genius of
|
62 |
|
63 |
-
## How Does Techdocs Work Its Magic? 🔮
|
64 |
|
65 |
##### Just feed your code into **Techdocs**, and like a seasoned wizard, it'll conjure up beautifully detailed documentation in an instant. Your code will transform into a masterpiece of clarity, complete with insightful comments, vivid descriptions, crystal-clear parameters, return values, and real-world examples.
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
- ##### Boost your code quality effortlessly.
|
70 |
-
- ##### Share your brilliance with the world in a snap.
|
71 |
-
- ##### Effortlessly generate documentation for your code.
|
72 |
-
- ##### Include comments, descriptions, parameters, return values, and real-life examples.
|
73 |
-
- ##### Elevate your code's readability, maintainability, and quality.
|
74 |
-
|
75 |
-
##### **Techdocs** is your code's trusty companion, helping you document with ease so you can focus on what you do best: coding!. **Techdocs** is your secret weapon for leveling up your code game. Whether you're a seasoned developer or just starting your coding journey, Techdocs has got your back. Get ready to unlock the future of code documentation today! 🌟
|
76 |
-
|
77 |
-
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
|
|
|
|
|
|
|
|
|
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
|
|
|
|
|
84 |
)
|
85 |
|
|
|
86 |
if 'access_token' not in st.session_state:
|
87 |
st.session_state.runpage = auth_page
|
88 |
else:
|
|
|
19 |
data = f.read()
|
20 |
return base64.b64encode(data).decode()
|
21 |
|
22 |
+
st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!]🚀")
|
23 |
|
24 |
def logout():
|
25 |
del st.session_state["access_token"]
|
26 |
del st.session_state["refresh_token"]
|
27 |
del st.session_state["username"]
|
28 |
|
29 |
+
with st.sidebar.expander("🧑Account Details",expanded=True):
|
30 |
if 'username' not in st.session_state:
|
31 |
+
st.warning("Please Login or Signup to continue")
|
32 |
else:
|
33 |
+
st.info(f"Welcome, {st.session_state.username}! 😄")
|
34 |
+
if st.button("Logout 👋"):
|
35 |
logout()
|
36 |
+
st.rerun()
|
37 |
|
38 |
|
39 |
def home_page():
|
|
|
58 |
st.markdown(
|
59 |
"""
|
60 |
|
61 |
+
##### Unleash the documentation dynamo that is **Techdocs**! Say goodbye to the documentation drudgery that haunts coders' dreams and embrace the effortless power of AI-driven documentation. With **Techdocs**, harness the genius of LLama2, the magic of WizardCoderLM, the versatility of Huggingface Transformers, and the precision of Langchain and Clarifai.
|
62 |
|
63 |
+
## :rainbow[How Does Techdocs Work Its Magic?] 🔮
|
64 |
|
65 |
##### Just feed your code into **Techdocs**, and like a seasoned wizard, it'll conjure up beautifully detailed documentation in an instant. Your code will transform into a masterpiece of clarity, complete with insightful comments, vivid descriptions, crystal-clear parameters, return values, and real-world examples.
|
66 |
|
67 |
+
"""
|
68 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
with st.expander("What Can Techdocs Do for You? 🌟",expanded=True):
|
71 |
+
st.markdown(
|
72 |
+
"""
|
73 |
+
- ##### Boost your code quality effortlessly 🚀.
|
74 |
+
- ##### Share your brilliance with the world in a snap 🌏.
|
75 |
+
- ##### Effortlessly generate documentation for your code 🤖.
|
76 |
+
- ##### Include comments, descriptions, parameters, return values, and real-life examples 📃.
|
77 |
+
- ##### Elevate your code's readability, maintainability, and quality 📃.
|
78 |
+
"""
|
79 |
+
)
|
80 |
|
81 |
+
st.markdown(
|
82 |
+
"""
|
83 |
+
##### **Techdocs** is your code's trusty companion, helping you document with ease so you can focus on what you do best: coding!. **Techdocs** is your secret weapon for leveling up your code game. Whether you're a seasoned developer or just starting your coding journey, Techdocs has got your back. Get ready to unlock the future of code documentation today! 🌟
|
84 |
+
"""
|
85 |
+
)
|
86 |
|
87 |
+
st.markdown("""
|
88 |
+
## :rainbow[How to use Techdocs?]
|
89 |
+
##### Head over to the **Usage** page to get started!😄
|
90 |
+
""")
|
91 |
+
st.link_button("Usage", "http://localhost:8501/Usage_📝?page=Usage")
|
92 |
|
93 |
+
st.sidebar.divider()
|
94 |
+
st.sidebar.info(
|
95 |
+
"""
|
96 |
+
Follow us on:
|
97 |
|
98 |
+
Github → [@MayureshAgashe2105](https://github.com/MayureshAgashe2105)\n
|
99 |
+
Github → [@HemanthSai7](https://github.com/HemanthSai7)
|
100 |
+
"""
|
101 |
)
|
102 |
|
103 |
+
|
104 |
if 'access_token' not in st.session_state:
|
105 |
st.session_state.runpage = auth_page
|
106 |
else:
|
testing/DBQueries.py
CHANGED
@@ -9,18 +9,6 @@ class DBQueries:
|
|
9 |
|
10 |
@classmethod
|
11 |
def insert_to_database(cls, table_name: str, data: Union[Tuple, List[Tuple]], cols: List[str]=None):
|
12 |
-
"""
|
13 |
-
This method is used to insert data into a specified table in the database.
|
14 |
-
|
15 |
-
Args:
|
16 |
-
table_name (str): The name of the table where the data will be inserted.
|
17 |
-
data (Union[Tuple, List[Tuple]]): The data to be inserted into the table. It can be either a tuple or a list of tuples.
|
18 |
-
cols (List[str], optional): A list of column names in the table. If not provided, the method will assume that all columns are required. Defaults to None.
|
19 |
-
|
20 |
-
Raises:
|
21 |
-
TypeError: If the data is not a tuple or a list of tuples.
|
22 |
-
"""
|
23 |
-
'\n This method is used to insert data into a specified table in the database.\n\n Args:\n table_name (str): The name of the table where the data will be inserted.\n data (Union[Tuple, List[Tuple]]): The data to be inserted into the table. It can be either a tuple or a list of tuples.\n cols (List[str], optional): A list of column names in the table. If not provided, the method will assume that all columns are required. Defaults to None.\n\n Raises:\n TypeError: If the data is not a tuple or a list of tuples.\n '
|
24 |
con = DBConnection.get_client()
|
25 |
cursor = con.cursor()
|
26 |
QUERY = f"INSERT INTO {{table_name}} ({','.join(cols)}) VALUES ".format(table_name=table_name)
|
@@ -35,23 +23,6 @@ class DBQueries:
|
|
35 |
|
36 |
@classmethod
|
37 |
def fetch_data_from_database(cls, table_name: str, cols_to_fetch: Union[str, List[str]], where_clause: str=None):
|
38 |
-
"""
|
39 |
-
This method is a class method that fetches data from a specified table in the database based on the specified
|
40 |
-
column names and an optional WHERE clause.
|
41 |
-
|
42 |
-
Args:
|
43 |
-
- table_name (str): The name of the table from which to fetch data.
|
44 |
-
- cols_to_fetch (Union[str, List[str]]): The column(s) to fetch from the table. If a single string, it should
|
45 |
-
be a comma-separated list of column names.
|
46 |
-
- where_clause (str, optional): An optional WHERE clause to filter the fetched data. Defaults to None.
|
47 |
-
|
48 |
-
Returns:
|
49 |
-
- List[tuple]: A list of tuples, where each tuple represents a row of data fetched from the database.
|
50 |
-
|
51 |
-
Raises:
|
52 |
-
- None
|
53 |
-
"""
|
54 |
-
'\n This method is a class method that fetches data from a specified table in the database based on the specified\n column names and an optional WHERE clause.\n\n Args:\n - table_name (str): The name of the table from which to fetch data.\n - cols_to_fetch (Union[str, List[str]]): The column(s) to fetch from the table. If a single string, it should\n be a comma-separated list of column names.\n - where_clause (str, optional): An optional WHERE clause to filter the fetched data. Defaults to None.\n\n Returns:\n - List[tuple]: A list of tuples, where each tuple represents a row of data fetched from the database.\n\n Raises:\n - None\n '
|
55 |
con = DBConnection.get_client()
|
56 |
cursor = con.cursor()
|
57 |
if isinstance(cols_to_fetch, str):
|
@@ -65,21 +36,6 @@ class DBQueries:
|
|
65 |
|
66 |
@classmethod
|
67 |
def update_data_in_database(cls, table_name: str, cols_to_update: Union[str, List[str]], where_clause: str=None, new_values: Union[str, List[str]]=None):
|
68 |
-
"""
|
69 |
-
This function is used to update data in a specific table in the database.
|
70 |
-
|
71 |
-
Args:
|
72 |
-
table_name (str): The name of the table in which the data needs to be updated.
|
73 |
-
cols_to_update (Union[str, List[str]]): The column(s) that need to be updated. If a single string, it should end with '=%s'. If a list, elements should be separated by '=%s, '.join(cols_to_update).
|
74 |
-
where_clause (str, optional): The WHERE clause to specify the condition for updating the data. Defaults to None.
|
75 |
-
new_values (Union[str, List[str]], optional): The new values that need to be updated in the specified columns. If a single string, it should be a list of new values. Defaults to None.
|
76 |
-
|
77 |
-
Returns:
|
78 |
-
bool: Returns True if the data is successfully updated in the database.
|
79 |
-
|
80 |
-
Raises:
|
81 |
-
None
|
82 |
-
"""
|
83 |
con = DBConnection.get_client()
|
84 |
cursor = con.cursor()
|
85 |
if isinstance(cols_to_update, str):
|
|
|
9 |
|
10 |
@classmethod
|
11 |
def insert_to_database(cls, table_name: str, data: Union[Tuple, List[Tuple]], cols: List[str]=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
con = DBConnection.get_client()
|
13 |
cursor = con.cursor()
|
14 |
QUERY = f"INSERT INTO {{table_name}} ({','.join(cols)}) VALUES ".format(table_name=table_name)
|
|
|
23 |
|
24 |
@classmethod
|
25 |
def fetch_data_from_database(cls, table_name: str, cols_to_fetch: Union[str, List[str]], where_clause: str=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
con = DBConnection.get_client()
|
27 |
cursor = con.cursor()
|
28 |
if isinstance(cols_to_fetch, str):
|
|
|
36 |
|
37 |
@classmethod
|
38 |
def update_data_in_database(cls, table_name: str, cols_to_update: Union[str, List[str]], where_clause: str=None, new_values: Union[str, List[str]]=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
con = DBConnection.get_client()
|
40 |
cursor = con.cursor()
|
41 |
if isinstance(cols_to_update, str):
|
testing/test.py
CHANGED
@@ -1,105 +1,18 @@
|
|
1 |
def add(a, b):
|
2 |
-
"""
|
3 |
-
This function adds two numbers.
|
4 |
-
|
5 |
-
Arguments:
|
6 |
-
a (int): The first number to be added.
|
7 |
-
b (int): The second number to be added.
|
8 |
-
|
9 |
-
Returns:
|
10 |
-
int: Returns the sum of the two numbers.
|
11 |
-
|
12 |
-
Raises:
|
13 |
-
TypeError: If the input is not an integer.
|
14 |
-
"""
|
15 |
-
'\n This function adds two numbers.\n\n Arguments:\n a (int): The first number to be added.\n b (int): The second number to be added.\n\n Returns:\n int: Returns the sum of the two numbers.\n\n Raises:\n TypeError: If the input is not an integer.\n '
|
16 |
return a + b
|
17 |
|
18 |
def multiply(a, b):
|
19 |
-
"""
|
20 |
-
This function multiplies two given numbers.
|
21 |
-
|
22 |
-
Arguments:
|
23 |
-
a (int or float): The first number to be multiplied.
|
24 |
-
b (int or float): The second number to be multiplied.
|
25 |
-
|
26 |
-
Returns:
|
27 |
-
int or float: The product of the two numbers.
|
28 |
-
|
29 |
-
Raises:
|
30 |
-
TypeError: If the input types are not numbers (int or float).
|
31 |
-
|
32 |
-
"""
|
33 |
-
'\n This function multiplies two given numbers.\n\n Arguments:\n a (int or float): The first number to be multiplied.\n b (int or float): The second number to be multiplied.\n\n Returns:\n int or float: The product of the two numbers.\n\n Raises:\n TypeError: If the input types are not numbers (int or float).\n\n '
|
34 |
return a * b
|
35 |
|
36 |
def subtract(a, b):
|
37 |
-
"""
|
38 |
-
This function subtracts the second number from the first number.
|
39 |
-
|
40 |
-
Args:
|
41 |
-
a (int): The first number to be subtracted.
|
42 |
-
b (int): The second number to be subtracted from the first number.
|
43 |
-
|
44 |
-
Returns:
|
45 |
-
int: Returns the result of the subtraction.
|
46 |
-
|
47 |
-
Raises:
|
48 |
-
TypeError: If the input arguments are not integers.
|
49 |
-
"""
|
50 |
-
'\n This function subtracts the second number from the first number.\n\n Args:\n a (int): The first number to be subtracted.\n b (int): The second number to be subtracted from the first number.\n\n Returns:\n int: Returns the result of the subtraction.\n\n Raises:\n TypeError: If the input arguments are not integers.\n '
|
51 |
return a - b
|
52 |
|
53 |
def divide(a, b):
|
54 |
-
"""
|
55 |
-
This function divides the first argument by the second argument.
|
56 |
-
|
57 |
-
Arguments:
|
58 |
-
a (float): First argument to be divided.
|
59 |
-
b (float): Second argument by which the first argument is to be divided.
|
60 |
-
|
61 |
-
Returns:
|
62 |
-
float: Returns the result of the division of the first argument by the second argument.
|
63 |
-
|
64 |
-
Raises:
|
65 |
-
ValueError: If the second argument is zero, it raises a ValueError with the message 'Cannot divide by zero'.
|
66 |
-
"""
|
67 |
-
"\n This function divides the first argument by the second argument.\n\n Arguments:\n a -- First argument to be divided. It should be a float.\n b -- Second argument by which the first argument is to be divided. It should be a float.\n\n Returns:\n float -- Returns the result of the division of the first argument by the second argument.\n\n Raises:\n ValueError -- If the second argument is zero, it raises a ValueError with the message 'Cannot divide by zero'.\n "
|
68 |
if b == 0:
|
69 |
raise ValueError('Cannot divide by zero')
|
70 |
return a / b
|
71 |
|
72 |
def func(*args, **kwargs):
|
73 |
-
"""
|
74 |
-
This function is a decorator that wraps another function and returns a new function that acts as a wrapper.
|
75 |
-
|
76 |
-
Arguments:
|
77 |
-
func (function): The function to be wrapped.
|
78 |
-
* args (tuple): Positional arguments to be passed to the wrapped function.
|
79 |
-
* kwargs (dict): Keyword arguments to be passed to the wrapped function.
|
80 |
-
|
81 |
-
Returns:
|
82 |
-
A new function that acts as a wrapper for the original function.
|
83 |
-
|
84 |
-
Raises:
|
85 |
-
None
|
86 |
-
"""
|
87 |
-
'\nThis function is a decorator that wraps another function and returns a new function that acts as a wrapper.\n\nArgs:\n func (function): The function to be wrapped.\n\nKwargs:\n Any additional keyword arguments are passed to the wrapped function.\n\nReturns:\n A new function that acts as a wrapper for the original function.\n\nRaises:\n None\n'
|
88 |
-
|
89 |
def wrapper(*args, **kwargs):
|
90 |
-
"""
|
91 |
-
This function performs a specific operation on a list of integers.
|
92 |
-
|
93 |
-
Arguments:
|
94 |
-
n (int): The size of the list.
|
95 |
-
k (int): The value to be searched in the list.
|
96 |
-
|
97 |
-
Returns:
|
98 |
-
A list of integers representing the result of the operation.
|
99 |
-
|
100 |
-
Raises:
|
101 |
-
ValueError: If the input arguments are not integers.
|
102 |
-
"""
|
103 |
-
"\n This function is a wrapper that calls another function (specified by 'func') with the given arguments.\n\n Arguments:\n * args (tuple): Positional arguments to be passed to 'func'.\n * kwargs (dict): Keyword arguments to be passed to 'func'.\n\n Returns:\n Whatever 'func' returns.\n\n Raises:\n Whatever exceptions 'func' raises.\n "
|
104 |
return func(*args, **kwargs)
|
105 |
return wrapper
|
|
|
1 |
def add(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
return a + b
|
3 |
|
4 |
def multiply(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
return a * b
|
6 |
|
7 |
def subtract(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
return a - b
|
9 |
|
10 |
def divide(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
if b == 0:
|
12 |
raise ValueError('Cannot divide by zero')
|
13 |
return a / b
|
14 |
|
15 |
def func(*args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def wrapper(*args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return func(*args, **kwargs)
|
18 |
return wrapper
|