diff --git a/ME.md b/ME.md new file mode 100644 index 00000000..b93a907e --- /dev/null +++ b/ME.md @@ -0,0 +1,5 @@ +A Ynov depuis la B1, je code en principalement Python +j'ai des compétences en Docker, git, en gestion de bdd et traitement des donné + +J'aime faire du piano + diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfer_log.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfer_log.txt new file mode 100644 index 00000000..059978e6 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfer_log.txt @@ -0,0 +1,6 @@ +2024-03-01 15:51:29.892625: user_accounts/BYVDXVCP.txt -> 1.0 -> user_accounts/CLHKWFZS.txt +2024-03-01 15:52:28.958875: user_accounts/BYVDXVCP.txt -> 5.0 -> user_accounts/CLHKWFZS.txt +2024-03-01 16:01:35.194715: user_accounts/ZBCWMUYL.txt -> 47 -> user_accounts/LZGACVCF.txt +2024-03-01 16:01:36.903238: user_accounts/PYUVBYYF.txt -> 56 -> user_accounts/ZBCWMUYL.txt +2024-03-01 16:01:38.071986: user_accounts/LXGJEAWF.txt -> 12 -> user_accounts/CLHKWFZS.txt +2024-03-01 16:01:39.318381: user_accounts/LXGJEAWF.txt -> 37 -> user_accounts/ZBCWMUYL.txt diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfert.py b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfert.py new file mode 100644 index 00000000..b5efd6d9 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/transfert.py @@ -0,0 +1,123 @@ +import random +import string +import os +from datetime import datetime +import sys + + +def transfer(source, dest, amount): + if source == dest: + print("Source and destination accounts cannot be the same.") + return + + if "user_accounts" not in source: + source = "user_accounts/" + source + if "user_accounts" not in dest: + dest = "user_accounts/" + dest + + try: + with open(source, 'r') as source_file: + source_balance = float(source_file.read().strip()) + + with open(dest, 'r') as dest_file: + dest_balance = float(dest_file.read().strip()) + + if source_balance < amount: + print("Insufficient funds in the source account.") + return + + source_balance -= amount + dest_balance += amount + + with open( source, 'w') as source_file: + source_file.write(str(source_balance)) + + with open( dest, 'w') as dest_file: + dest_file.write(str(dest_balance)) + + print(f"Transfer of {amount} completed successfully.") + with open('transfer_log.txt', 'a') as log_file: + log_file.write(f"{datetime.now()}: {source} -> {amount} -> {dest} \n") + + except FileNotFoundError: + print("One or both of the users does not exist.") + except ValueError: + print("File content is not a valid number.") + except Exception as e: + print(f"An error occurred: {e}") + + + +def create_random_users(num_users): + try: + os.makedirs("user_accounts", exist_ok=True) + + for i in range(num_users): + + username = ''.join(random.choices(string.ascii_uppercase, k=8)) + + user_file = f"{username}.txt" + + balance = 100 + + with open('user_accounts/'+ user_file, 'w') as file: + file.write(str(balance)) + + print(f"User {i+1}: Username - {username}, Source File - {user_file}, Balance - {balance}") + + except Exception as e: + print(f"An error occurred: {e}") + + + +def get_random_user_accounts(): + user_files = os.listdir("user_accounts") + + if len(user_files) < 2: + print("Insufficient user accounts to perform transactions.") + return None, None + + user1_file = random.choice([file for file in user_files]) + user2_file = random.choice([file for file in user_files if file != user1_file]) + + return user1_file, user2_file + + + +def perform_random_transaction(): + # Get two random user accounts + user1_file, user2_file = get_random_user_accounts() + + if user1_file is None or user2_file is None: + return + + try: + # Extract usernames from file names + user1 = user1_file + user2 = user2_file + print(f"Performing transaction from {user1} to {user2}") + + # Generate a random amount for the transaction + amount = random.randint(10, 100) + + # Perform the transaction + transfer(user1, user2, amount) + + except Exception as e: + print(f"An error occurred: {e}") + + + +# create_random_users(7) +# perform_random_transaction() + + + +if __name__ == '__main__': + args = sys.argv + + if len(args) == 4: + transfer(args[1], args[2], float(args[3])) + else: + perform_random_transaction() + diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/BYVDXVCP.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/BYVDXVCP.txt new file mode 100644 index 00000000..f2511044 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/BYVDXVCP.txt @@ -0,0 +1 @@ +93.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/CLHKWFZS.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/CLHKWFZS.txt new file mode 100644 index 00000000..a4946b65 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/CLHKWFZS.txt @@ -0,0 +1 @@ +119.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LXGJEAWF.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LXGJEAWF.txt new file mode 100644 index 00000000..26dc50d0 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LXGJEAWF.txt @@ -0,0 +1 @@ +51.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LZGACVCF.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LZGACVCF.txt new file mode 100644 index 00000000..563743d1 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/LZGACVCF.txt @@ -0,0 +1 @@ +147.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PRBUBWPD.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PRBUBWPD.txt new file mode 100644 index 00000000..7730ef7f --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PRBUBWPD.txt @@ -0,0 +1 @@ +89 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PYUVBYYF.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PYUVBYYF.txt new file mode 100644 index 00000000..2df99911 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/PYUVBYYF.txt @@ -0,0 +1 @@ +55.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/ZBCWMUYL.txt b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/ZBCWMUYL.txt new file mode 100644 index 00000000..3ab199c9 --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/chain_scipt/user_accounts/ZBCWMUYL.txt @@ -0,0 +1 @@ +146.0 \ No newline at end of file diff --git a/adventure/BLOCKCHAIN/william.dubois@ynov.com/ipfs_id b/adventure/BLOCKCHAIN/william.dubois@ynov.com/ipfs_id new file mode 100644 index 00000000..a190ec2d --- /dev/null +++ b/adventure/BLOCKCHAIN/william.dubois@ynov.com/ipfs_id @@ -0,0 +1 @@ +12D3KooWCQ75AUpcQNWFa1k4SmxjUXAevJcR1HLznG6pZX8tVo7V \ No newline at end of file