CLI.-.Pastes.mp4
It is Inspired from ( https://github.com/codemyst/pastemyst )
This script allows users to create, view, and manage text pastes. It provides a simple command-line interface for creating new pastes and viewing existing ones.
create
: Create a new paste.view
: View an existing paste.exit
: Exit the script.
The script imports several modules including
json
----------->for parsing and generating JSON data
platform
------>to access underlying platform’s identifying data
os
-------------->for a portable way of using operating system dependent functionality
rich.console
->enables rich text and beautiful formatting in the terminal
rich.syntax
-->allows syntax highlighting of code snippets
questionary
-->for creating interactive prompts and questionnaires
pyperclip
---->access to the clipboard for copying and pasting
random
------->used for generating random numbers and selecting random elements
string
------->provides a collection of string constants, useful for generating random strings
- The script checks if a
JSON
file named 'UserData.json' exists.
- If it doesn't exist, it creates a new one and stores the user's operating system information in it.
- The script also defines a function 'update_json' that updates the user's data in a JSON file named 'data.json'.
- The script then enters a while loop that prompts the user to select an action: create, view, or exit.
- If the user selects 'create', the script prompts for confirmation, paste name, and checks the user's operating system.
- If the operating system is Windows, it creates an empty text file, opens it with notepad, reads the entered data, and stores it in a variable 'pdData'.
- The script then generates a unique ID and checks if it already exists in the 'data.json' file.
- If it doesn't exist, it updates the JSON file with the paste name, ID, and data, and removes the temporary text file.
- If the user selects 'view', the script prompts for an ID and checks if it exists in the 'data.json' file.
- If it exists, it prints the paste content using the rich.syntax module, prompts the user to copy the content to the clipboard, and copies it if requested.
- If the user selects 'exit', the script breaks out of the while loop and terminates.
- If an unknown command is entered, the script prints a message to try again.