Skip to content
69 changes: 69 additions & 0 deletions Projects/Message_Encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import random as ra

Check failure on line 1 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (INP001)

Projects/Message_Encryption.py:1:1: INP001 File `Projects/Message_Encryption.py` is part of an implicit namespace package. Add an `__init__.py`.
import string as str

Check failure on line 2 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (A004)

Projects/Message_Encryption.py:2:18: A004 Import `str` is shadowing a Python builtin


def options():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: options. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function options

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function options

Please provide return type hint for the function: options. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function options

Please provide return type hint for the function: options. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function options

Please provide return type hint for the function: options. If the function does not return a value, please provide the type hint as: def function() -> None:

while True:
print("========== Welcome To Message Encryption ==========")
print("\t'1' For Encryption")
print("\t'2' For Decode")
try:
opt = int(input("Enter: "))
if opt not in ("1", "2", 1, 2):
print("Choose Number Between '1','2'")
if opt == 1:
encrypt()
elif opt == 2:
decode()
except ValueError:
print("Enter Numbers Only")


def encrypt():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: encrypt. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function encrypt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function encrypt

Please provide return type hint for the function: encrypt. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function encrypt

Please provide return type hint for the function: encrypt. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function encrypt

Please provide return type hint for the function: encrypt. If the function does not return a value, please provide the type hint as: def function() -> None:

x = input("Enter Your Message :")

if len(x) <= 3:
encrypt_key = input("Enter Your Key '1','4','7' :")

with open("User_Key.txt", "a+") as f:
f.write(f"{encrypt_key},{x}\n")
print(f"Successfully Encrypted: {x[::-1]}")

encrypt_key = input("Enter Your Key '1','4','7' :")

with open("User_Key.txt", "a") as f:
f.write(f"{encrypt_key},{x}\n")
shift = x[1:] + x[0]
prefix = "".join(ra.choice(str.ascii_letters) for _ in range(3))
suffix = "".join(ra.choice(str.ascii_letters) for _ in range(3))
message = prefix + shift + suffix
message = message.strip()
print(f"Successfully Encrypted: {message}")
return encrypt_key


def decode():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: decode. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function decode

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function decode

Please provide return type hint for the function: decode. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function decode

Please provide return type hint for the function: decode. If the function does not return a value, please provide the type hint as: def function() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/Message_Encryption.py, please provide doctest for the function decode

Please provide return type hint for the function: decode. If the function does not return a value, please provide the type hint as: def function() -> None:

with open("User_Key.txt", "r") as f:

Check failure on line 46 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (UP015)

Projects/Message_Encryption.py:46:31: UP015 Unnecessary mode argument help: Remove mode argument
user_message = input("Enter Message To Decode : ")
decode_key = input("Enter Your Key : ")
found = False

for line in f:
encrypt_key, x = line.strip().split(",")

if encrypt_key == decode_key:
if len(user_message) <= 3:
print(user_message[::-1])
else:
x = user_message[3:-3]
x = x[-1] + x[:-1]
print(f"Message Decoded : {x}")

found = True
break

if not found:
print("Didn't Match :/")


options()
81 changes: 81 additions & 0 deletions Projects/News.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import requests

Check failure on line 1 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (INP001)

Projects/News.py:1:1: INP001 File `Projects/News.py` is part of an implicit namespace package. Add an `__init__.py`.
import sys

Check failure on line 2 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

Projects/News.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports


def options():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/News.py, please provide doctest for the function options

Please provide return type hint for the function: options. If the function does not return a value, please provide the type hint as: def function() -> None:


print("-" * 5, "Welcome To Daily News", "-" * 5)
print("Enter 1 For Headlines")
print("Enter 2 For Topic's")
print("Enter 3 For Geting News From Your API :)")
print("Enter 4 For Exit")

while True:
try:
choose = int(input("Choose :"))
match choose:
case 1:
return Fatch_News()
case 2:
return search()
case 3:
return Fatch_Key()
case 4:
return Exit()

except ValueError:
print("Enter Numbers Only")


def Fatch_Key():

Check failure on line 30 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (N802)

Projects/News.py:30:5: N802 Function name `Fatch_Key` should be lowercase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Fatch_Key

As there is no test file in this pull request nor any test function or class in the file Projects/News.py, please provide doctest for the function Fatch_Key

Please provide return type hint for the function: Fatch_Key. If the function does not return a value, please provide the type hint as: def function() -> None:


user_key = input("Enter Your API Key :")
return Fatch_News(user_key)


def search():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file Projects/News.py, please provide doctest for the function search

Please provide return type hint for the function: search. If the function does not return a value, please provide the type hint as: def function() -> None:

pass


def Fatch_News(user_key=""): # Enter Your API Key Heare

Check failure on line 40 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (N802)

Projects/News.py:40:5: N802 Function name `Fatch_News` should be lowercase

url = f"https://newsapi.org/v2/everything?q=keyword&apiKey={user_key}"
request = requests.get(url)

Check failure on line 43 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (S113)

Projects/News.py:43:15: S113 Probable use of `requests` call without timeout
data = request.json()

news = []

for article in data["articles"]:
news.append(
{
"Title": article["title"],
"Author": article["author"],
"Description": article["description"],
}
)

return news


def Exit():

Check failure on line 60 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (N802)

Projects/News.py:60:5: N802 Function name `Exit` should be lowercase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Exit

As there is no test file in this pull request nor any test function or class in the file Projects/News.py, please provide doctest for the function Exit

Please provide return type hint for the function: Exit. If the function does not return a value, please provide the type hint as: def function() -> None:


print("Thanks For Using PDF Tool Kit :)")
sys.exit()


# Run These Command To Get Info About Type Of Data We Are Dealing With
def Data_Info():

Check failure on line 67 in Projects/News.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (N802)

Projects/News.py:67:5: N802 Function name `Data_Info` should be lowercase
"""Tell Abut Type Of Data We Are Grtting From URL"""

url = "https://newsapi.org/v2/everything?q=keyword&apiKey=6495169f47154cfd83e9ac94ed500b0a"
request = requests.get(url)

data = request.json()

print(type(data))
print(data.keys())
print(data["articles"][0].keys())


if __name__ == "__main__":
options()
8 changes: 6 additions & 2 deletions genetic_algorithm/basic_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def mutate(child: str, genes: list[str]) -> str:
"""
child_list = list(child)
if random.uniform(0, 1) < MUTATION_PROBABILITY:
child_list[random.randint(0, len(child)) - 1] = random.choice(genes)
random_index = random.randint(0, len(child) - 1)
child_list[random_index] = random.choice(genes)

return "".join(child_list)


Expand Down Expand Up @@ -175,7 +177,9 @@ def basic(target: str, genes: list[str], debug: bool = True) -> tuple[int, int,

# Flush the old population, keeping some of the best evolutions.
# Keeping this avoid regression of evolution.
population_best = population[: int(N_POPULATION / 3)]
population_best = [
item[0] for item in population_score[: int(N_POPULATION / 3)]
]
population.clear()
population.extend(population_best)
# Normalize population score to be between 0 and 1.
Expand Down
Loading