lundi 18 juin 2018

Python - Print out once when hit the if-else statement

So I have been trying to play around abit with monitor - For those who doesn't know what monitoring is - basically what it means is that you are checking something etc element, url or whatever in a certain time and check again if it has been changed.

What I want to do is that the program is doing a requests from the beginning to get the website URL - The url will automatic be redirected either to /password or without it.

Then what I do is to check if password contains the URL - If it does.. Make a print out that password page is up and then send to discord only ONCE while it can print out password page is up as command but it should only print out to discord ONCE!

Then opposite if the password changes from /password to no password - it should say password page is down and then print out that it is down and send to discord ONCE that is has been down

This is what I have done and

url = 'mrcnoir'

while True:
        try:
            password_page = requests.get('https://{}.com'.format(url))
            password_page.raise_for_status()

        except:
            print('Error checking password page! - https://{}.com'.format(url))
            continue



        else:
            # *************---If password up---**************

            if ('password' in password_page.url):

                        # Password page is up
                        print('Password page is up! - ' + 'https://{}.com'.format(url))

                        if not ('password' in password_page.url):

                            # No password page -> password page


                            # *************---Send to discord---**************

                            print("SENDING...1") #Discord function will be added later

                            time.sleep(random.randint(6, 12))


            # *************---If password down---**************

            else:
                # Password page is down
                print('Password page is down! - ' + 'https://{}.com'.format(url))
                if ('password' in password_page.url):

                    # Password page -> no password page


                    # *************---Send---**************

                    print("SENDING...2") #Discord function will be added laterthis print...

                    time.sleep(random.randint(6, 12))

        # *************---Retry between 6-12 random.---**************
        finally:
            time.sleep(random.randint(6, 12))

The problem im having now is that it never enters the if statements inside the else functions meaning it will never hit the "Send to discord" function ...

How would I be able to make it go through so it sends to my discord (no function is needed right now, a simple print out inside the function is fine for now) only once?

It could been so I have made the if statement wrong aswell....

Aucun commentaire:

Enregistrer un commentaire