Hi when I disconnect the internet I get an error NameError: name 'self' is not 
defined. I really dont get it.. thanks all. Is that a bug? or my fault?


Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\programming Alon\stock market app\PROJECT\AlonStockMarket.py", line 
93, in secret
    print(ping('google.com'))
  File "C:\programming Alon\stock market app\PROJECT\AlonStockMarket.py", line 
72, in ping
    conn.connect((addr, 80))
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 
"C:\Users\Alon\AppData\Local\Programs\Python\Python37-32\lib\threading.py", 
line 917, in _bootstrap_inner
    self.run()
  File 
"C:\Users\Alon\AppData\Local\Programs\Python\Python37-32\lib\threading.py", 
line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\programming Alon\stock market app\PROJECT\AlonStockMarket.py", line 
95, in secret
    self.pushButton.setDisabled(True)
NameError: name 'self' is not defined






this is my code:


import sys
import requests
from lxml import html
import requests
import urllib.request, urllib.error, urllib.parse
import _thread
from PyQt5 import QtCore, QtGui, QtWidgets
import time
import threading
import ctypes  # An included library with Python install.

global flag
global loopexit
global UserSymbol
global RadioButtonBellow
global UserSymbol
global UserStockPrice 
global RadioButtonAbove
global SMScheckBox
global varUser
global varPass


varUser=0
varPass=0
UserSymbol=0
RadioButtonBellow=0
RadioButtonAbove=0
UserSymbol=0
UserStockPrice=0

loopexit=0




from urllib.request import urlopen

import time
import random
import struct
import select
import socket


def chk(data):
    x = sum(x << 8 if i % 2 else x for i, x in enumerate(data)) & 0xFFFFFFFF
    x = (x >> 16) + (x & 0xFFFF)
    x = (x >> 16) + (x & 0xFFFF)
    return struct.pack('<H', ~x & 0xFFFF)


import time
import random
import struct
import select
import socket


def chk(data):
    x = sum(x << 8 if i % 2 else x for i, x in enumerate(data)) & 0xFFFFFFFF
    x = (x >> 16) + (x & 0xFFFF)
    x = (x >> 16) + (x & 0xFFFF)
    return struct.pack('<H', ~x & 0xFFFF)


def ping(addr, timeout=1, number=1, data=b''):
    with socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) as 
conn:
        payload = struct.pack('!HH', random.randrange(0, 65536), number) + data

        conn.connect((addr, 80))
        conn.sendall(b'\x08\0' + chk(b'\x08\0\0\0' + payload) + payload)
        start = time.time()

        while select.select([conn], [], [], max(0, start + timeout - 
time.time()))[0]:
            data = conn.recv(65536)
            if len(data) < 20 or len(data) < struct.unpack_from('!xxH', 
data)[0]:
                continue
            if data[20:] == b'\0\0' + chk(b'\0\0\0\0' + payload) + payload:
                return time.time() - start

def secret():
    flag=0
    while True:
           flag=0
           time.sleep(5)
           try:
            
            if flag==1:
              self.pushButton.setDisabled(False)
              flag=0
            print(ping('google.com'))
           except:
            self.pushButton.setDisabled(True)
            flag=1
            def Mbox(title, text, style):
                      return ctypes.windll.user32.MessageBoxW(0, text, title, 
style)
            Mbox('Problem', 'No internet connection', 1 )   
           
            print("No internet connection")

t2 = threading.Thread(target=secret) 
t2.start()


def myfunction():
    import paramiko
    import sys
    global RadioButtonBellow
    global UserSymbol
    global UserStockPrice 
    global RadioButtonAbove
    global varUser
    global varPass
  

    RadioButtonBellow=str(RadioButtonBellow)
    varUser=str(varUser)
    UserSymbol=str(UserSymbol)
    UserStockPrice=str(UserStockPrice)
    RadioButtonAbove=str(RadioButtonAbove)

 

    from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_AlonStockMarketApp(object):
    def setupUi(self, AlonStockMarketApp):
        AlonStockMarketApp.setObjectName("AlonStockMarketApp")
        AlonStockMarketApp.resize(799, 591)
        font = QtGui.QFont()
        font.setPointSize(16)
        AlonStockMarketApp.setFont(font)
        icon = QtGui.QIcon()
        
icon.addPixmap(QtGui.QPixmap("../../../Users/Alon/Downloads/Alon/icon.png"), 
QtGui.QIcon.Normal, QtGui.QIcon.Off)
        AlonStockMarketApp.setWindowIcon(icon)
        self.radioButton = QtWidgets.QRadioButton(AlonStockMarketApp)
        self.radioButton.setGeometry(QtCore.QRect(90, 250, 191, 24))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.radioButton.setFont(font)
        self.radioButton.setObjectName("radioButton")
        self.buttonGroup_2 = QtWidgets.QButtonGroup(AlonStockMarketApp)
        self.buttonGroup_2.setObjectName("buttonGroup_2")
        self.buttonGroup_2.addButton(self.radioButton)
        self.checkBox = QtWidgets.QCheckBox(AlonStockMarketApp)
        self.checkBox.setGeometry(QtCore.QRect(320, 510, 131, 17))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.checkBox.setFont(font)
        self.checkBox.setObjectName("checkBox")
        self.checkBox_2 = QtWidgets.QCheckBox(AlonStockMarketApp)
        self.checkBox_2.setGeometry(QtCore.QRect(320, 540, 141, 17))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.checkBox_2.setFont(font)
        self.checkBox_2.setObjectName("checkBox_2")
        self.radioButton_2 = QtWidgets.QRadioButton(AlonStockMarketApp)
        self.radioButton_2.setGeometry(QtCore.QRect(310, 250, 186, 24))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.radioButton_2.setFont(font)
        self.radioButton_2.setObjectName("radioButton_2")
        self.buttonGroup_2.addButton(self.radioButton_2)
        self.pushButton = QtWidgets.QPushButton(AlonStockMarketApp)
        self.pushButton.setEnabled(True)
        self.pushButton.setGeometry(QtCore.QRect(90, 520, 72, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        self.radioButton_3 = QtWidgets.QRadioButton(AlonStockMarketApp)
        self.radioButton_3.setGeometry(QtCore.QRect(90, 310, 191, 24))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.radioButton_3.setFont(font)
        self.radioButton_3.setObjectName("radioButton_3")
        self.buttonGroup = QtWidgets.QButtonGroup(AlonStockMarketApp)
        self.buttonGroup.setObjectName("buttonGroup")
        self.buttonGroup.addButton(self.radioButton_3)
        self.radioButton_4 = QtWidgets.QRadioButton(AlonStockMarketApp)
        self.radioButton_4.setGeometry(QtCore.QRect(310, 310, 186, 24))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.radioButton_4.setFont(font)
        self.radioButton_4.setObjectName("radioButton_4")
        self.buttonGroup.addButton(self.radioButton_4)
        self.pushButton_2 = QtWidgets.QPushButton(AlonStockMarketApp)
        self.pushButton_2.setGeometry(QtCore.QRect(30, 20, 75, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setObjectName("pushButton_2")
        self.textEdit_4 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_4.setGeometry(QtCore.QRect(330, 393, 221, 38))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.textEdit_4.setFont(font)
        self.textEdit_4.setObjectName("textEdit_4")
        self.textEdit_5 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_5.setGeometry(QtCore.QRect(330, 350, 221, 38))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.textEdit_5.setFont(font)
        self.textEdit_5.setObjectName("textEdit_5")
        self.label = QtWidgets.QLabel(AlonStockMarketApp)
        self.label.setGeometry(QtCore.QRect(80, 180, 151, 16))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_2.setGeometry(QtCore.QRect(370, 180, 71, 16))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_3.setGeometry(QtCore.QRect(180, 360, 121, 20))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_4.setGeometry(QtCore.QRect(160, 400, 171, 20))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_5.setGeometry(QtCore.QRect(170, 30, 351, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(18)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.pushButton_3 = QtWidgets.QPushButton(AlonStockMarketApp)
        self.pushButton_3.setGeometry(QtCore.QRect(180, 520, 72, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setObjectName("pushButton_3")
        self.textEdit = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit.setGeometry(QtCore.QRect(240, 170, 121, 38))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.textEdit.setFont(font)
        self.textEdit.setObjectName("textEdit")
        self.textEdit_7 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_7.setGeometry(QtCore.QRect(450, 170, 221, 38))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.textEdit_7.setFont(font)
        self.textEdit_7.setObjectName("textEdit_7")
        self.minimize = QtWidgets.QPushButton(AlonStockMarketApp)
        self.minimize.setGeometry(QtCore.QRect(564, 20, 91, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.minimize.setFont(font)
        self.minimize.setObjectName("minimize")
        self.pushButton_4 = QtWidgets.QPushButton(AlonStockMarketApp)
        self.pushButton_4.setGeometry(QtCore.QRect(20, 90, 101, 41))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_4.setFont(font)
        self.pushButton_4.setObjectName("pushButton_4")
        self.textEdit_2 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_2.setGeometry(QtCore.QRect(410, 450, 121, 38))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.textEdit_2.setFont(font)
        self.textEdit_2.setObjectName("textEdit_2")
        self.label_8 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_8.setGeometry(QtCore.QRect(180, 460, 221, 16))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.label_7 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_7.setGeometry(QtCore.QRect(420, 90, 85, 23))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.label_6 = QtWidgets.QLabel(AlonStockMarketApp)
        self.label_6.setGeometry(QtCore.QRect(130, 90, 44, 23))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.textEdit_3 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_3.setGeometry(QtCore.QRect(510, 80, 253, 41))
        self.textEdit_3.setObjectName("textEdit_3")
        self.textEdit_6 = QtWidgets.QTextEdit(AlonStockMarketApp)
        self.textEdit_6.setGeometry(QtCore.QRect(180, 80, 221, 41))
        self.textEdit_6.setObjectName("textEdit_6")

        self.retranslateUi(AlonStockMarketApp)
        QtCore.QMetaObject.connectSlotsByName(AlonStockMarketApp)

        
        self.pushButton.clicked.connect(self.printMessage)
        self.radioButton.toggled.connect(self.myradioButton1_function)
        self.radioButton_2.toggled.connect(self.myradioButton2_function)
        self.pushButton_3.clicked.connect(self.stopButton)
        self.checkBox.stateChanged.connect(self.SMScheckBox)
        self.minimize.clicked.connect(self.Minimize)
        self.textEdit.setTabChangesFocus(True)
        self.textEdit_5.setTabChangesFocus(True)
        self.textEdit_4.setTabChangesFocus(True)
        self.textEdit_7.setTabChangesFocus(True)
        
        
    def Minimize(self):
        import win32gui, win32con
        import os
        import math
        import time
        time.sleep(2)
        Minimize = win32gui.GetForegroundWindow()
        win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE)

    def SMScheckBox(self):
        global SMScheckBox
        if self.checkBox.isChecked()==True:
            print("hi checkbox")
        else:
            print("no")

    
    def myradioButton1_function(self):
        global RadioButtonAbove
        if self.radioButton.isChecked():
                print ('Above is Checked')    
                RadioButtonAbove=self.radioButton.isChecked()
                RadioButtonBellow=self.radioButton_2.isChecked()
                
    def myradioButton2_function(self):
        global RadioButtonBellow
        if self.radioButton_2.isChecked():
                print ('Bellow is Checked')
                RadioButtonBellow=self.radioButton_2.isChecked()
                RadioButtonAbove=self.radioButton.isChecked()

    def printMessage(self):
         global UserSymbol
         global UserStockPrice
         global RadioButtonBellow
         global RadioButtonAbove
         global varUser
         global varPass
         varUser=self.textEdit_5.toPlainText()
         varPass=self.textEdit_4.toPlainText()
         UserSymbol=self.textEdit.toPlainText()
         UserSymbol=UserSymbol[0:4]
         UserStockPrice=self.textEdit_7.toPlainText()
          
         if  not varPass or not varUser or UserSymbol==0 or UserStockPrice==0 
or (RadioButtonAbove==0 and RadioButtonBellow==0):
             def Mbox(title, text, style):
                  return ctypes.windll.user32.MessageBoxW(0, text, title, style)
             Mbox('you need to enter all data first', 'you need to choose Stock 
value,price,bellow/above price', 1 )
           
         else:
              self.pushButton.setDisabled(True)
              self.pushButton_3.setDisabled(False)
              
              UserStockPrice=float(UserStockPrice)
              UserSymbol=str(UserSymbol)
              t = threading.Thread(target=myfunction) 
              t.start()
              
    def stopButton(self):
        global loopexit
        loopexit=1
        self.pushButton.setDisabled(False)
        self.pushButton_3.setDisabled(True)
        



    def retranslateUi(self, AlonStockMarketApp):
        _translate = QtCore.QCoreApplication.translate
        AlonStockMarketApp.setWindowTitle(_translate("AlonStockMarketApp", 
"Dialog"))
        self.radioButton.setText(_translate("AlonStockMarketApp", "Above Price 
(x>)"))
        self.checkBox.setText(_translate("AlonStockMarketApp", "SMS ALERT"))
        self.checkBox_2.setText(_translate("AlonStockMarketApp", "GMAIL ALERT"))
        self.radioButton_2.setText(_translate("AlonStockMarketApp", "Bellow 
Price (x<)"))
        self.pushButton.setText(_translate("AlonStockMarketApp", "START"))
        self.radioButton_3.setText(_translate("AlonStockMarketApp", "Get alert 
once a day"))
        self.radioButton_4.setText(_translate("AlonStockMarketApp", "Get alert 
every time"))
        self.pushButton_2.setText(_translate("AlonStockMarketApp", "EXIT"))
        self.textEdit_4.setHtml(_translate("AlonStockMarketApp", "<!DOCTYPE 
HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" 
\"http://www.w3.org/TR/REC-html40/strict.dtd\";>\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; 
font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br 
/></p></body></html>"))
        self.textEdit_5.setHtml(_translate("AlonStockMarketApp", "<!DOCTYPE 
HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" 
\"http://www.w3.org/TR/REC-html40/strict.dtd\";>\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; 
font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br 
/></p></body></html>"))
        self.label.setText(_translate("AlonStockMarketApp", "SYMBOL of stock:"))
        self.label_2.setText(_translate("AlonStockMarketApp", "PRICE :"))
        self.label_3.setText(_translate("AlonStockMarketApp", "User of Gmail:"))
        self.label_4.setText(_translate("AlonStockMarketApp", "Password of 
Gmail:"))
        self.label_5.setText(_translate("AlonStockMarketApp", "ALON STOCK 
MARKET APP"))
        self.pushButton_3.setText(_translate("AlonStockMarketApp", "STOP"))
        self.textEdit.setHtml(_translate("AlonStockMarketApp", "<!DOCTYPE HTML 
PUBLIC \"-//W3C//DTD HTML 4.0//EN\" 
\"http://www.w3.org/TR/REC-html40/strict.dtd\";>\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; 
font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br 
/></p></body></html>"))
        self.textEdit_7.setHtml(_translate("AlonStockMarketApp", "<!DOCTYPE 
HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" 
\"http://www.w3.org/TR/REC-html40/strict.dtd\";>\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; 
font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br 
/></p></body></html>"))
        self.minimize.setText(_translate("AlonStockMarketApp", "Minimize"))
        self.pushButton_4.setText(_translate("AlonStockMarketApp", "Sign In"))
        self.textEdit_2.setHtml(_translate("AlonStockMarketApp", "<!DOCTYPE 
HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" 
\"http://www.w3.org/TR/REC-html40/strict.dtd\";>\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; 
font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; 
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br 
/></p></body></html>"))
        self.label_8.setText(_translate("AlonStockMarketApp", "Phone number 
(for SMS):"))
        self.label_7.setText(_translate("AlonStockMarketApp", "Password:"))
        self.label_6.setText(_translate("AlonStockMarketApp", "User:"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    AlonStockMarketApp = QtWidgets.QDialog()
    ui = Ui_AlonStockMarketApp()
    ui.setupUi(AlonStockMarketApp)
    AlonStockMarketApp.show()
    sys.exit(app.exec_())

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to