samedi 13 février 2021

Else is an invalid syntax

I wrote some code that will download a webpage and then search for a certain string, i know this is an inefficient way to do it but it is the way i chose, anyways the code always comes up with an invalid syntax for else. Any help is welcome! code:

import requests
from discord import Webhook, RequestsWebhookAdapter

#download website and turns into a .txt file
while true:
    print('Beginning file download with requests')
    url = str(input("Enter Profile ID:"))
    r = requests.get(url)
    with open('/Users/Computer/Desktop/Notification/[profile.txt', 'wb') as f:
     f.write(r.content)

# Retrieve HTTP meta-data
print(r.status_code)
print(r.headers['content-type'])
print(r.encoding)
#opens text file and searches for a certain keyword
with open('/Users/Computer/Desktop/Notification/[profile.txt') as f:
    if 'avatar-status online profile-avatar-status icon-online' in f.read():#if it finds the keyword it sleeps and then retries
        time.sleep(20)
    continue
#if it doesnt find the keyword (meaning they are offline) it sends you a message through discord webhook
    else:
    webhook = Webhook.from_url("YOUR WEBHOOK HERE!", adapter=RequestsWebhookAdapter())
    webhook.send("Found string")

Aucun commentaire:

Enregistrer un commentaire