-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (53 loc) · 2.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
from datetime import datetime as dt
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi
from sys import argv
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
loadUi('GUI.ui',self)
self.Handel_buttons()
self.redirect="127.0.0.1"
self.host="C:\Windows\System32\drivers\etc\hosts"
self.websites = []
def Handel_buttons(self):
self.pushButton.clicked.connect(self.add)
self.pushButton_2.clicked.connect(self.start)
def add(self):
self.blockedWebsite= 'www.' + (self.lineEdit.text())
self.websites.append(self.blockedWebsite)
self.lineEdit.clear()
print(self.websites)
def start(self):
self.FROM=self.timeEdit.text()
self.From_std=int(self.FROM[0:2])
self.From_min=int(self.FROM[3:])
self.TO=self.timeEdit_2.text()
self.To_std=int(self.TO[0:2])
self.To_min=int(self.TO[3:])
if dt(dt.now().year,dt.now().month,dt.now().day,self.From_std,self.From_min)<dt.now()<dt(dt.now().year,dt.now().month,dt.now().day,self.To_std,self.To_min):
with open(self.host,'r+') as self.file:
self.content=self.file.readlines()
for self.website in self.websites:
if (f'{self.redirect} {self.website} \n') in self.content:
print('there is a website')
pass
else:
self.content.insert(20,f'{self.redirect} {self.website} \n')
self.file.seek(0)
self.file.writelines(self.content)
else:
with open(self.host,'r+') as self.file:
self.content=self.file.readlines()
for self.website in self.websites:
if (f'{self.redirect} {self.website} \n') in self.content:
self.content.remove(f'{self.redirect} {self.website} \n')
self.file.seek(0)
self.file.writelines(self.content)
app = QApplication(argv)
window = MainWindow()
window.show()
app.exec_()