Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dat-removal #12

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CS_Source Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ def delete_roll():
os.rename("temp.dat", "stud.dat")
input("Press any key to continue....")

if not os.path.isfile("stud.dat"):
print("'stud.dat' file doesn't exist.")
print("1 -> Generate a new empty file")
print("2 -> Generate a file with fake data")

print(40 * "=")
choice = input("Enter your choice: ")
print(40 * "=")

if choice == "1":
try:
file = open("stud.dat", "wb")
file.close()
print("New empty file 'stud.dat' created.")
except Exception as e:
print(f"Error: {e}")
elif choice == "2":
print("Generating fake data...")
os.system("python create_dat.py")
print("Fake data generated.")
else:
print("Invalid choice!")
time.sleep(1)


while True:
os.system("cls")
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ For every school, an important task for the administration department is to mana

- [MySQL](https://dev.mysql.com/downloads/mysql/)
- [MySQL Python Connector](https://dev.mysql.com/downloads/connector/python/)
- fake
```bash
pip install fake
```

##### 2. Install MySQL in Python using below command

Expand Down
37 changes: 37 additions & 0 deletions create_dat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from fake import Faker
import random
import pickle

class Student:
def __init__(self, roll, name, percentage):
self.roll = roll
self.name = name
self.percentage = percentage

def generate_fake_records(n):
fake = Faker()
records = []

for _ in range(n):
roll = random.randint(1000, 9999)
name = fake.name()
percentage = round(random.uniform(50, 100), 2)

student = Student(roll, name, percentage)
records.append(student)

return records

def save_to_dat(records):
try:
with open("fake_stud.dat", "wb") as file:
for record in records:
pickle.dump(record, file)
print(f"{len(records)} fake records saved to fake_stud.dat")
except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":
n = int(input("Enter the number of fake records to generate: "))
fake_records = generate_fake_records(n)
save_to_dat(fake_records)
Loading