Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xdearboy authored May 18, 2024
0 parents commit 68e2ac1
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 xdearboy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<p align="center">
<a href="https://github.com/xdearboy/pastecreator/graphs/contributors">
<img src="https://img.shields.io/github/contributors/xdearboy/pastecreator.svg?style=for-the-badge" alt="Contributors Shield"/>
</a>
<a href="https://github.com/xdearboy/pastecreator/network/members">
<img src="https://img.shields.io/github/forks/xdearboy/pastecreator.svg?style=for-the-badge" alt="Forks Shield"/>
</a>
<a href="https://github.com/xdearboy/pastecreator/stargazers">
<img src="https://img.shields.io/github/stars/xdearboy/pastecreator.svg?style=for-the-badge" alt="Stars Shield"/>
</a>
<a href="https://github.com/xdearboy/pastecreator/issues">
<img src="https://img.shields.io/github/issues/xdearboy/pastecreator.svg?style=for-the-badge" alt="Issues Shield"/>
</a>
<a href="https://github.com/xdearboy/pastecreator/blob/master/LICENSE.txt">
<img src="https://img.shields.io/github/license/xdearboy/pastecreator.svg?style=for-the-badge" alt="License Shield"/>
</a>
</p>


<!-- PROJECT LOGO -->
<br />
<div align="center">
<a href="https://github.com/xdearboy/pastecreator">
<img src="banner.jpg" alt="Banner">
</a>

<h3 align="center">pastecreator</h3>

<p align="center">
<p align="center">
Convenient application in two views - CLI/GUI, which automates uploading a paste to Pastebin.
<br />
<br />
<a href="https://small.fileditchstuff.me/s11/VUQRPxHbDPTvlIBkPzzT.gif">View Demo</a>
·
<a href="https://github.com/xdearboy/pastecreator/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
·
<a href="https://github.com/xdearboy/pastecreator/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
</p>
</div>

--------------------------------------

### Prerequisites

Before you begin, ensure you have met the following requirements:

* You have installed the latest version of `python/pastecreator`
* You have a `Windows/Linux/Mac` machine.

--------------------------------------

### Installation

1. **Clone the repository**

```sh
git clone https://github.com/xdearboy/pastecreator.git
```

2. **Install the dependencies**

```sh
pip3 install -r requirements.txt
```

3. **Run the application**

```sh
python3 main.py
```

--------------------------------------

### Demo

![Demo](demo.gif)

--------------------------------------

### Contributing

Contributions are **welcome** and will be fully **credited**.

You can contribute in many ways:

* By using alpha, beta, and pre-releases
* By reporting bugs
* By suggesting new features
* By fixing issues
* By reviewing pull requests

We use [Github Flow](https://guides.github.com/introduction/flow/index.html),
so fork the repo and create your branch from `master`.

--------------------------------------

### Authors

* [xdearboy](https://github.com/xdearboy)

--------------------------------------



Binary file added banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import flet
from flet import TextField, ElevatedButton, Column, Page, Text, icons, IconButton, Row
from src.pastebin_poster import PastebinPoster


def post_to_pastebin(page, content, title, result_text):
poster = PastebinPoster()
response = poster.post_to_pastebin(content, title)
result_text.value = response
page.update()


def switch_theme(page, theme_button):
new_theme = "light" if page.theme_mode == "dark" else "dark"
page.theme_mode = new_theme
theme_button.icon = icons.DARK_MODE if new_theme == "light" else icons.LIGHT_MODE
page.update()


def main(page):
page.title = "Pastebin Poster | by xdearboy"
page.auto_size = True

theme_button = IconButton(
icon=icons.LIGHT_MODE,
on_click=lambda e: switch_theme(page, theme_button),
tooltip="Change theme",
)
header_row = Row(
controls=[Text(value="Pastebin Poster", size=20), theme_button],
alignment="spaceBetween",
)

title_field = TextField(label="Write the title of the paste", width=400)
content_field = TextField(label="Write the content of the paste", multiline=True, expand=True)
result_text = Text()

def post_click(event):
post_to_pastebin(page, content_field.value, title_field.value, result_text)

submit_button = ElevatedButton(text="Post to Pastebin", on_click=post_click)

main_column = Column(
controls=[header_row, title_field, content_field, submit_button, result_text],
expand=True,
spacing=10,
)

page.add(main_column)


if __name__ == "__main__":
flet.app(target=main)
60 changes: 60 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from importlib import metadata
import subprocess
import sys

ORANGE = "\033[38;2;255;165;0m"
RED = "\033[38;2;255;0;0m"
END = "\033[0m"


def colored_print(text, color=ORANGE):
print(color + text + END)


def is_package_installed(package_name):
try:
metadata.version(package_name)
return True
except metadata.PackageNotFoundError:
return False


def install_packages():
required_packages = ["selenium", "flet", "webdriver-manager"]
for package in required_packages:
if not is_package_installed(package):
colored_print(f"Installing {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
colored_print(f"{package} successfully installed.")


def post_to_pastebin(content, title):
from src.pastebin_poster import PastebinPoster

poster = PastebinPoster()
return poster.post_to_pastebin(content, title)


def main():
interface_type = input(
"@admin ➜ /pastecreater $~ Choose an interface (CLI/GUI): "
).strip().lower()

if interface_type == "cli":
content = input("@admin ➜ /pastecreater $~ Write the content of the paste : ")
title = input("@admin ➜ /pastecreater $~ Write the title of the paste: ")
url = post_to_pastebin(content, title)
colored_print(f"The paste is published: {url}")
elif interface_type == "gui":
import flet
from gui import main as gui_main

flet.app(target=gui_main)
else:
colored_print("Incorrect interface selection.", RED)
sys.exit(1)


if __name__ == "__main__":
install_packages()
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
selenium
flet
webdriver-manager
Empty file added src/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions src/pastebin_poster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import (
TimeoutException,
NoSuchElementException,
ElementNotInteractableException,
)
import time
import platform


class PastebinPoster:
def __init__(self):
options = Options()
self.operating_system = platform.system()
options.headless = True
if self.operating_system == "Linux":
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=2560,1080")
service = Service(ChromeDriverManager().install())
self.browser = webdriver.Chrome(service=service, options=options)
self.wait = WebDriverWait(self.browser, 10)

def post_to_pastebin(self, content, title):
try:
self.browser.get("https://pastebin.com")
assert "Pastebin" in self.browser.title

text_area = self.wait.until(
EC.presence_of_element_located(
(By.XPATH, '//textarea[@id="postform-text"]')
)
)
self.browser.execute_script("arguments[0].scrollIntoView(true);", text_area)
text_area.send_keys(content)

title_input = self.wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input#postform-name"))
)
self.browser.execute_script(
"arguments[0].scrollIntoView(true);", title_input
)
title_input.send_keys(title)

submit_button = self.wait.until(
EC.element_to_be_clickable((By.CLASS_NAME, "btn.-big"))
)
self.browser.execute_script(
"arguments[0].scrollIntoView(true);", submit_button
)
self.wait.until(EC.visibility_of(submit_button))
self.browser.execute_script("arguments[0].click();", submit_button)

self.browser.implicitly_wait(5)
time.sleep(1)
print(f"Post created: {self.browser.current_url}")
return self.browser.current_url
except (
TimeoutException,
NoSuchElementException,
ElementNotInteractableException,
) as e:
print(f"Error: {e}")
finally:
self.browser.quit()

0 comments on commit 68e2ac1

Please sign in to comment.