Merge pull request #1 from assenzostefano/main

I fixed some things.
This commit is contained in:
archnotwindows 2022-07-29 23:21:49 +02:00 committed by GitHub
commit f731041979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 68 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
executable.py
executable.sh
siti.dat
history.txt
history.csv
test.py
.~lock.history.csv#

View File

@ -1,5 +1,51 @@
# poweroffer
# PowerOffer
this simple program will allow you to not procrastinate and to have a break from the PC during the day :)
<p align="center">
<br>
<a href="https://github.com/archnotwindows/poweroffer/">
<img alt="Repo Size" src="https://img.shields.io/github/repo-size/archnotwindows/poweroffer?logo=github">
</a>
<a href="https://github.com/archnotwindows/poweroffer/issues">
<img alt="Issues" src="https://img.shields.io/github/issues/archnotwindows/poweroffer?logo=github">
</a>
<a href="https://github.com/archnotwindows/poweroffer/pulls">
<img alt="Pull requests" src="https://img.shields.io/github/issues-pr/archnotwindows/poweroffer?logo=github">
</a>
</p>
<p align="center">
<br>
<a href="https://github.com/archnotwindows/poweroffer/fork">
<img alt="Forks" src="https://img.shields.io/github/forks/archnotwindows/poweroffer?logo=github">
</a>
<a href="https://img.shields.io/github/stars/archnotwindows/poweroffer">
<img alt="Stars" src="https://img.shields.io/github/stars/archnotwindows/poweroffer?logo=github">
</a>
to see all the installation steps check the wiki session of this repository :)
Poweroffer is a small and simple Python program that is used to remove distractions (like Youtube) and not procrastinate.
## Getting Started
- Install **[Python](https://python.org)** on your machine. **Version 3.10 or higher is required!**
- Clone the repository on your machine.
- Open your console in the cloned repository.
- To complete the installation, write the following command in the console:
```console
pip install -r requirements.txt
```
- To start Poweroffer, write the following command in the console:
```console
python main.py
```
## 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:)
[![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/)

97
main.py
View File

@ -1,22 +1,43 @@
#Libraries for create a window
import tkinter as tk
#Libraries for execute 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
window = tk.Tk()
#Resolution program
window.geometry("800x500")
window.title("poweroffer")
#Title program
window.title("Poweroffer")
#Background program
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)
@ -24,64 +45,14 @@ sito = tk.StringVar
text_input= tk.Entry(textvariable=sito)
text_input.grid(row=3, column=0, sticky="WE", padx=10, pady=10)
def spegni():
subprocess.run('shutdown now', shell=True)
subprocess.run('shutdown -s -t O', shell=True)
def smetti():
sito = text_input.get()
print(sito)
f = open ("siti.dat","w")
f.write(sito)
f.close()
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()
b = open("executable.sh", "w")
b.write("#!/bin/bash\n")
b.write("/home/lorenzo/Scrivania/poweroffer/executable.py")
b.close()
second_button= tk.Button(text="Stop procrastinating", command=smetti)
#Button stop procrastinating
second_button= tk.Button(text="Stop procrastinating")
second_button.grid(row=5, column=0, sticky="WE", padx=15, pady=8)
first_button = tk.Button(text="have a break from the pc", command=spegni)
#Button for shutdown pc
first_button = tk.Button(text="have a break from the pc")
first_button.grid(row=1, column=0, sticky="W", padx=50, pady=50)
#Always open window
if __name__ == "__main__":
window.mainloop()