Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Fix: Access localhost webpage; close #10 #13 #11

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
60 changes: 48 additions & 12 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Code of Conduct

## v1 - Drafted by Izaac Saleh & Sukhwan Ko
## Versions

- v2 - Drafted by Sukhwan Ko
- <s>v1 - Drafted by Izaac Saleh & Sukhwan Ko</s>

## Our Pledge

Expand Down Expand Up @@ -55,22 +58,29 @@ any moderations they deem appropriate.

---

- Our online platform (website, forum, chatroom etc.)
- Code repository (including comments, pull requests, issue reports etc.)
- Project-related communication channels such as:
- Email
- Slack
- Microsoft Teams
- Discord
- Asana
- etc.
- In-person events(Conferences, meetups etc.)
**Our online platform**

- **Website**: The Code of Conduct applies to all comments, posts, and messages left on the website, including those in forums, discussion boards, or comment sections.
- **Forum**: The same rules apply to all discussions, threads, and topics within the forum, including those that are public or private.
- **Chatroom**: The Code of Conduct covers all conversations, messages, and files shared in chatroom, whether they're public or invited-only.

**Code repository**

- **Comments**: The Code applies to all comments left on code snippets, commits, or pull requests, as well as any replies or discussions that might arise.
- **Pull requests:** The same rules apply to all pull requests, including those for new features, bug fixes, or refactoring code.
- **Issue reports**: The Code of conduct covers all issue reports, whether they're related to bugs, feature requests, or documentation updates.

**Project-related communication channels**

- **Email**: The Code applies to all emails sent to the project's email list, including these that are public or private.
- **Microsoft Teams:** The Code of Conduct covers all discussions, meetings, and file shared within the project's Microsoft Teams space.
- **Discord(main):** The same rules apply to all voice or text chats, channels, and servers used by the project on Discord.

## Enforcement

---

Community leaders will take action to address violations of the Code of Conduct. The specific consequences will depend on the severity of the violation.
Our Community Leaders are responsible for clarifying and enforcing the standards of acceptable behaviour and are expected to lead by example. If a breach of the Code of Conduct is found to have occurred, Community Leaders are charged with taking appropriate but fair corrective action. Community Leaders have the responsibility, and maintain the right, to remove, edit, or reject comments, commits, code, issues, and other contributions that are not in alignment with this Code of Conduct. They will communicate the reasons for any moderation they deem appropriate.

## Enforcement Guidelines

Expand Down Expand Up @@ -100,6 +110,32 @@ Community leaders will take action to address violations of the Code of Conduct.

- **Consequence:** A permanent ban from any sort of public interaction within the community.

5. Additional Guidelines

- Initial Response: Upon receiving a report of potential Code of Conduct violation, our Community Leaders will acknowledge receipt and promptly investigate.
- Investigation Process:
- Gather information from all parties involved.
- Review relevant records and communications.
- Investigate in a fair and impartial manner.
- Communication During Investigation:
- Maintain open communication with all parties involved.
- Provide updates on the progress and outcome of the investigation.
- Decision-Making:
- Community Leaders will make decisions based on the findings and evidence gathered during the investigation.
- Consequences for Repeat Offenders:
- For repeat offenders, consequences may be escalated or combined (e.g., temporary ban and loss of privileges).
- Appeals Process:
- Establish a clear appeals process for individuals affected by enforcement decisions.
- Ensure that appeals are heard in a fair and impartial manner.

6. Resolving Disputes

- Dispute Resolution Committee: Establish a committee composed of community leaders to resolve disputes related to Code of Conduct violations.
- Dispute Resolution Process:
- Identify the nature of the dispute.
- Gather information from all parties involved.
- Make a fair and impartial decision.

## Attribution

This Code of Conduct is adapted from the GITHUB documents template for "code of conduct" found when adding a file of the
Expand Down
16 changes: 12 additions & 4 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import sys
import os.path
import logging
import shutil
Expand All @@ -9,6 +11,8 @@
import html
import glob

sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))

# Initialise flask app
app = Flask(__name__, static_url_path='/static', static_folder='static')
# Current video
Expand Down Expand Up @@ -230,9 +234,9 @@ def update_settings():
def reset_settings():
print("Current working directory:", os.getcwd())
# Delete the existing config.ini file
if os.path.exists('config.ini'):
os.remove('config.ini')
shutil.copy('config.example.ini', 'config.ini')
if os.path.exists('app/config.ini'):
os.remove('app/config.ini')
shutil.copy('app/config.example.ini', 'app/config.ini')
current_settings = utils.get_current_settings()
return render_template('settings.html', current_settings=current_settings)

Expand Down Expand Up @@ -275,9 +279,13 @@ def update_tesseract_path():
if __name__ == "__main__":
host = "localhost"
port = 5000
if utils.update_port():
port = 5002
else:
port = port
logging.basicConfig(filename="app.log", filemode="w", level=logging.DEBUG, format="%(levelname)s - %(message)s")
print("[*] Starting OcrRoo Server")
print(f"[*] OcrRoo Server running on http://{host}:{port}/")
app.run(host=host, port=port)
app.run(host=host, port=port, debug=True)
else:
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s - %(message)s")
45 changes: 29 additions & 16 deletions app/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os.path
import hashlib
import json
import os.path
import shutil
import subprocess
import logging
Expand All @@ -14,6 +15,8 @@
from pytube.exceptions import RegexMatchError
from configparser import ConfigParser

sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))


def config(section: str = None, option: str = None) -> Union[ConfigParser, str]:
"""
Expand All @@ -27,9 +30,9 @@ def config(section: str = None, option: str = None) -> Union[ConfigParser, str]:
if (section is None) != (option is None):
raise SyntaxError("section AND option parameters OR no parameters must be passed to function config()")
parser = ConfigParser()
if not os.path.exists("config.ini"):
shutil.copy("config.example.ini", "config.ini")
parser.read("config.ini")
if not os.path.exists("app/config.ini"):
shutil.copy("app/config.example.ini", "app/config.ini")
parser.read("app/config.ini")
if parser.get("AppSettings", "openai_api_key") != "your_openai_api_key_here":
openai.api_key = parser.get("AppSettings", "openai_api_key")
# TODO: This only needs to be set once, unsure if calling this will cause any performance issues same for
Expand Down Expand Up @@ -82,15 +85,15 @@ def read_user_data() -> json:
Reads the users data from json file
:return: Returns user data as json
"""
if not os.path.exists("data\\userdata.json"):
if not os.path.exists("data\\"):
os.makedirs("data\\")
with open("data\\userdata.json", "w") as user_data:
if not os.path.exists("app/data/userdata.json"):
if not os.path.exists("app/data/"):
os.makedirs("app/data/")
with open("app/data/userdata.json", "w") as user_data:
user_data.write(json.dumps({"all_videos": []}))
pass
return None
try:
with open("data\\userdata.json", "r") as user_data_json:
with open("app/data/userdata.json", "r") as user_data_json:
data = json.load(user_data_json)
return data
except JSONDecodeError:
Expand Down Expand Up @@ -266,7 +269,7 @@ def update_user_video_data(filename: str, progress: Optional[float] = None, capt
record["progress"] = round(progress)
if capture is not None:
record["captures"].append(capture)
with open("data/userdata.json", "w") as json_data:
with open("app/data/userdata.json", "w") as json_data:
json.dump(user_data, json_data, indent=4)


Expand Down Expand Up @@ -294,9 +297,9 @@ def add_video_to_user_data(filename: str, video_title: str, video_hash: str, you
return
thumbnail = str(int(time.time())) + ".png"
# Check if img dir exists if not create
if not os.path.exists("static/img"):
os.makedirs("static/img")
cv2.imwrite(f"static/img/{thumbnail}", frame)
if not os.path.exists("app/static/img"):
os.makedirs("app/static/img")
cv2.imwrite(f"app/static/img/{thumbnail}", frame)
new_video = {
"video_hash": video_hash,
"filename": filename,
Expand All @@ -310,7 +313,7 @@ def add_video_to_user_data(filename: str, video_title: str, video_hash: str, you
new_video["youtube_url"] = youtube_url
video_capture.release()
user_data["all_videos"].append(new_video)
with open("data/userdata.json", "w") as json_data:
with open("app/data/userdata.json", "w") as json_data:
json.dump(user_data, json_data, indent=4)


Expand Down Expand Up @@ -444,7 +447,7 @@ def delete_video_from_userdata(filename: str) -> None:
if current_video["filename"] == filename:
all_videos.remove(current_video)
break
with open("data/userdata.json", "w") as json_data:
with open("app/data/userdata.json", "w") as json_data:
json.dump(user_data, json_data, indent=4)


Expand All @@ -465,7 +468,7 @@ def update_configuration(new_values_dict) -> None:
value = str(value)
config_file.set(section, key, value)
# save the file
with open('config.ini', 'w') as config_file_save:
with open('app/config.ini', 'w') as config_file_save:
config_file.write(config_file_save)


Expand Down Expand Up @@ -530,3 +533,13 @@ def extract_form_values(request):
'use_youtube_downloader': youtube_downloader_enabled,
}
}


def update_port() -> bool:
"""
Checks if the current platform is a Unix-based system (like Darwin or Linux). If so, returns True.
:return: bool - True if running on a Unix-based system, False otherwise
"""
if sys.platform.lower() in ['darwin', 'linux']:
return True
return False
9 changes: 8 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tests remain fast and do not modify external state.
"""
import os

import sys
from app import utils


Expand Down Expand Up @@ -140,3 +140,10 @@ def test_file_already_exists_false(mocker):
def test_file_already_exists_no_user_data(mocker):
mocker.patch("app.utils.read_user_data", return_value=None)
assert not utils.file_already_exists("4aj3sdl5a4k2sjd091u091j")


def test_set_port_for_macos():
port = 5000
if sys.platform.lower() in ["darwin", 'linux']:
port = 5002
assert not port == 5000
Loading