diff --git a/README.md b/README.md index 86181b3..73e5611 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,76 @@ -# poweroffer +# Poweroffer -this simple program will allow you to not procrastinate and to have a break from the PC during the day :) +
+
+
+
+
+
+
+
+
-to see all the installation steps check the wiki session of this repository :)
+Whith this simple python program you will be able to not procrastinate during the day in some sort of website (like Youtube) that you can choose! so try it out!!
+## Getting Started
+ **WARNING!! to use this software you must use a linux distro and the Firefox web browser**
+
+0 - Install **[Python](https://python.org)** on your machine. **Version 3.10 or higher is required!**
+
+1 - Clone the repository on your machine.
+
+2 - Put the poweroffer extracted folder in the Desktop
+
+0 - Install tkinter with these commands "sudo apt-get install python3-tk" and "pip install tk"
+
+1 - Install os,json and time ( but probably these libraries are already installed on your system)
+
+2 - become a root user ( with " su " command and continue to do all the operations with root)
+
+3 - Install lz4.block with this command "pip install lz4"
+
+4 - download all the repository files and put the poweroffer folder in your desktop
+
+5 - open a terminal emulator and write "crontab -e" ( if is your first time you may have to choose witch editor you wanna use)
+
+6 - write at the end of the file this string " * * * * * /bin/bash /home/your-username/Desktop/poweroffer/executable.sh "
+
+7 - close the editor and save the changes
+
+8 - search for this file "recovery.jsonlz4" and copy it's path
+
+9 - edit the main.py file and scroll down until you see this
+
+![Istantanea_2022-07-21_14-07-03](https://user-images.githubusercontent.com/108471111/180209819-e4a4d0e0-80db-4a75-8689-e00b6b1ed44a.png)
+
+
+10 - replace the selected area with the path you have copied
+
+11 - exit from the root user and login to your everyday user
+
+11 - open a terminal and run the index.py file using " python3 index.py " to execute the program ( use this command every time you wanna run my program :)
+
+
+
+## License
+
+This project is licensed under either of:
+- [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.html)
+
+## Contact
+
+[![gmail](https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=Gmail&logoColor=white)](mailto:lorenzo020406@gmail.com)
+[![github](https://img.shields.io/badge/GitHub-000000?style=for-the-badge&logo=GitHub&logoColor=white)](https://github.com/archnotwindows)
+[![twitter](https://img.shields.io/badge/Twitter-007fff?style=for-the-badge&logo=twitter&logoColor=white)](https://twitter.com/Lollopro59_)
+[![instagram](https://img.shields.io/badge/Instagram-8f00ff?style=for-the-badge&logo=instagram&logoColor=white)](https://www.instagram.com/lollog020406/)
+[![stackoverflow](https://img.shields.io/badge/StackOverFlow-FF8000?style=for-the-badge&logo=stackoverflow&logoColor=white)](https://stackoverflow.com/users/19628082/archnotwindows)
\ No newline at end of file
diff --git a/main.py b/main.py
index 962d130..453ad36 100644
--- a/main.py
+++ b/main.py
@@ -1,56 +1,70 @@
-#Libraries for create a window
+#Libraries for create window
import tkinter as tk
-#Libraries for execute command
+#Libraries for run command
import subprocess
-#Libraries for read web browser history
-from browser_history import get_history
-#Libraries for date time
-from datetime import datetime
-#Libraries for read csv
-import csv
-#Print all browser history on cvs
-outputs = get_history()
-outputs.save("history.csv")
-
-#Get current date
-now = datetime.now()
-date_time_str = now.strftime("%Y-%m-%d %H:%M")
-print('DateTime String:', date_time_str)
-
-#Search Youtube Link on history.csv
-how_to_search = 'https://www.youtube.com/'
-rows = []
-with open('history.csv', 'rt') as f:
- reader = csv.reader(f, delimiter=',')
- for line in reader:
- if how_to_search in line:
- print("Yes!")
-
-#Create a window
+#Create window
window = tk.Tk()
-#Resolution program
+#Dimensional window
window.geometry("800x500")
-#Title program
-window.title("Poweroffer")
-#Background program
+#Title window
+window.title("poweroffer")
window.configure(background="blue")
window.grid_columnconfigure(0, weight=1)
#Welcome text
scritta = tk.Label(window, text="Welcome!", font=("Helvetica",15))
scritta.grid(row=0, column=0, sticky="N", padx=20, pady=10)
-
sito = tk.StringVar
text_input= tk.Entry(textvariable=sito)
text_input.grid(row=3, column=0, sticky="WE", padx=10, pady=10)
-#Button stop procrastinating
-second_button= tk.Button(text="Stop procrastinating")
+#Function for shutdown PC
+def spegni():
+ subprocess.run('shutdown now', shell=True)
+ subprocess.run('shutdown -s -t O', shell=True)
+
+#Function for shutdown PC when you visit YouTube and add website
+def smetti():
+ sito = text_input.get()
+ print(sito)
+ #Create siti.dat to save the sites to be checked, if you visit one of the sites listed, turn off your computer.
+ f = open ("siti.dat","w")
+ f.write(sito)
+ f.close()
+ #Read and save history web and if you visit one of the listed sites, turn off your computer.
+ a = open("executable.py","w")
+ a.write("#!/usr/bin/env python3 \n")
+ a.write("import os,json,lz4.block,time \n")
+ a.write("f = open(\"siti.dat\",\"r\") \n")
+ a.write("sito = f.read()\n")
+ a.write("d = open(\"/home/usr/snap/firefox/common/.mozilla/firefox/8gnxd9f4.default/sessionstore-backups/recovery.jsonlz4\", \"rb\") \n")
+ a.write("magic = d.read(8)\n")
+ a.write("data = json.loads(lz4.block.decompress(d.read()).decode(\"utf-8\"))\n")
+ a.write("d.close()\n")
+ a.write("current_window = \"\"\n")
+ a.write("for win in data.get(\"windows\"):\n")
+ a.write(" for tab in win.get(\"tabs\"):\n")
+ a.write(" i = int(tab.get(\"index\")) - 1 \n")
+ a.write(" current_window = tab.get(\"entries\")[i].get(\"url\")\n")
+ a.write("print(current_window)\n")
+ a.write("if sito in str(current_window):\n")
+ a.write(" print(\"Yes\")\n")
+ a.write(" os.system(\"shutdown now\")")
+ a.close()
+
+ #Create executable.sh for crontab (This way you can run the script every time you start your pc)
+ b = open("executable.sh", "w")
+ b.write("#!/bin/bash\n")
+ b.write("/home/lorenzo/Scrivania/poweroffer/executable.py")
+ b.close()
+
+#Stop procrastinating text
+second_button= tk.Button(text="Stop procrastinating", command=smetti)
second_button.grid(row=5, column=0, sticky="WE", padx=15, pady=8)
-#Button for shutdown pc
-first_button = tk.Button(text="have a break from the pc")
+#Have a break from the pc for shutdown PC
+first_button = tk.Button(text="have a break from the pc", command=spegni)
first_button.grid(row=1, column=0, sticky="W", padx=50, pady=50)
#Always open window
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..7d971ab
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+tk
\ No newline at end of file