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

Version1 dev #39

Closed
wants to merge 6 commits into from
Closed
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
Empty file added Autotype/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions Autotype/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from .core import Autotype
from .gui import App
import typer
import os


def main(cli: bool = True, gui: bool = False) -> None:
"""
A quick and small python script that helps you autotype on websites that have copy paste disabled like Moodle, HackerEarth contests etc as it is difficult to efficiently debug your code on an online compiler.

--cli --no-gui: for CLI

--gui --no-cli: for GUI

"""
if cli:
path: str = input("path: 🗂️ - ")
delay: int = int(input("delay: ⏰ - "))
if os.path.exists(path):
Autotype().type(path=path, delay=delay)
else:
print("Path Not Found")
if gui:
app = App()
app.start()


typer.run(main)
71 changes: 71 additions & 0 deletions Autotype/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
from dataclasses import dataclass
import os
import typer
from typing import Optional
from .core import Autotype
import time

@dataclass
class CLI:
@classmethod
def cli_options(
cls,
path: Optional[str] = typer.Option(
default="",
help=typer.style("the path to the file 🗂", fg=typer.colors.MAGENTA),
prompt=True,
confirmation_prompt=True,
show_default="Empty File Path",
),
delay: Optional[int] = typer.Option(
default=3,
help=typer.style(
"time ⌛️ delay before typing (in seconds)", fg=typer.colors.MAGENTA
),
show_default=3,
prompt=True,
)
):
"""
A quick and small python script that helps you autotype on websites that have copy paste disabled like Moodle, HackerEarth contests etc as it is difficult to efficiently debug your code on an online compiler.

--path: the path to the file.

--delay: time delay before typing.

return: Prints the File Given.
"""
if path and not os.path.isfile(path):
file_path = typer.style(
f"{path}",
fg=typer.colors.BRIGHT_WHITE,
bg=typer.colors.BRIGHT_RED,
bold=True,
)
error_message = typer.style(
"is not found Please Specify the correct Path.", fg=typer.colors.RED
)
typer.echo(f"{file_path + ' ' + error_message} ")
raise typer.Exit(code=0)
else:
total = 0
with typer.progressbar(
range(100),
label=typer.style(
"Writing File in Progress -> ", fg=typer.colors.GREEN, bold=True
),
) as progress:
for value in progress:
time.sleep(0.01)
total += 1
Autotype() .type(path, delay)
successfull_file_path = typer.style(
f"{path} File", fg=typer.colors.BRIGHT_GREEN
)
time_taken = typer.style(
f"is written in {abs(delay)} seconds", fg=typer.colors.BRIGHT_WHITE
)
typer.echo(f"{successfull_file_path + ' ' + time_taken}")


48 changes: 48 additions & 0 deletions Autotype/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pynput.keyboard import Key, Controller
from time import sleep
from dataclasses import dataclass


@dataclass
class Autotype:
"""

"""
default_delay: int = 3
default_code: str = """
class Main:
def __init__(self, name, age):
self.name = name
self.age = age

def __str__(self):
return f"The name is {self.name} and the age is {self.age{"
"""
@classmethod
def type(cls, path: str = None, delay: int = None, code: str = None):
"""

"""
if not delay:
delay = cls.default_delay

if delay < 0:
print()
delay = abs(cls.default_delay)

sleep(delay)

if path:
with open(path, "r") as File:
code = File.read()
elif code:
pass
else:
code = cls.default_code

keyboard = Controller()
for line in code.split("\n"):
keyboard.type(line)
sleep(0.1)
keyboard.tap(Key.enter)
keyboard.tap(Key.home)
17 changes: 6 additions & 11 deletions GUI_script.py → Autotype/gui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tkinter as tk
from Simulator import Type
from .core import Autotype
import customtkinter
from tkinter import filedialog
import tkinter
Expand Down Expand Up @@ -93,16 +93,16 @@ def start_typing(self):
delay = self.delay.get()
code = self.code.textbox.get("1.0", tk.END)
if str(code).isspace() and delay != "": # when code is not provided
Type(path=self.open_file(), delay=int(delay), code=None)
Autotype.type(path=self.open_file(), delay=int(delay), code=None)
self.label.configure(text="Done Writing Script")
elif str(code).isspace() and delay == "":
Type(path=self.open_file(), delay=int(delay), code=None)
Autotype.type(path=self.open_file(), delay=int(delay), code=None)
self.label.configure(text="Done Writing Script")
elif not str(code).isspace() and delay != "": # when code is provided
Type(path=None, delay=int(delay), code=code)
Autotype.type(path=None, delay=int(delay), code=code)
self.label.configure(text="Done Writing Script")
else:
Type(path=None, delay=int(delay), code=code)
Autotype.type(path=None, delay=int(delay), code=code)
self.label.configure(text="Done Writing Script")

def change_mode(self):
Expand All @@ -115,9 +115,4 @@ def on_closing(self, event=0):
self.destroy()

def start(self):
self.mainloop()


if __name__ == "__main__":
app = App()
app.start()
self.mainloop()
1 change: 0 additions & 1 deletion Simulator/__init__.py

This file was deleted.

36 changes: 0 additions & 36 deletions Simulator/simulate_keyboard.py

This file was deleted.

69 changes: 0 additions & 69 deletions command_line_script.py

This file was deleted.

Binary file removed requirements.txt
Binary file not shown.
49 changes: 49 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pathlib
from setuptools import setup

# The directory containing this file
HERE = pathlib.Path(__file__).parent

# The text of the README file
README = (HERE / "README.md").read_text()

# This call to setup() does all the work
setup(
name="Autotype",
version="1.0.0",
description="Autotype on websites that have copy-paste disabled like Moodle, HackerEarth contest etc.",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/tushar5526/Autotype",
author="Tushar Gupta",
author_email="tushar.gupta1026@gmail.com",
license="Creative Commons Zero v1.0 Universal",
classifiers=[
# "License :: OSI Approved :: CC0 1.0 Universal",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
],
packages=["Autotype"],
include_package_data=True,
install_requires=[
"click==8.1.3",
"colorama==0.4.5",
"customtkinter==4.6.3",
"darkdetect==0.7.1",
"importlib-metadata==5.0.0",
"Pillow==9.1.1",
"pynput==1.7.3",
"python-xlib==0.32",
"six==1.16.0",
"tk==0.1.0",
"typer==0.4.2",
"typing_extensions==4.4.0",
"zipp==3.10.0",
"pyobjc==7.3; sys_platform=='darwin'"
],
entry_points={
"console_scripts": [
"Autotype=Autotype.__main__:main",
]
},
)