• XSS.stack #1 – первый литературный журнал от юзеров форума

help

w999

HDD-drive
Пользователь
Регистрация
04.01.2022
Сообщения
21
Реакции
0
Properly name your topics
hello i am working on a program and need some assistance. essentially the part of the program im working on opens a text file and iterates through each line of the file to basically see whether or not that line in the file is either valid or invalid. the proble im having is i can't get the lines that come back valid to save to a seperate text file than. ive tried different varriations of for loops if statements and T/F and no luck. im very new to programming so any help is appreciated.

for example:
try:

good = 'valid'
f = open('xxx.txt', 'r')
f2 = open('yyy.txt', 'a')
list = open('xxx.txt').readlines()
for i in list:
f.readlines()
try:
url = 'https://xxx.com/' + i
html = requests.get(url).text
data = json.loads(html)
print(data.get('r').get(''))
time.sleep(5)

if i in list == good:
f2.writelines()
 
I think you're trying to do something like that

Python:
import requests

def my_checker(param):
    print('Start check:' + i)
    try:
        # make your http request here
        url = 'https://xxx.com/' + param
        resp = requests.get(url)
        data = resp.json()   # if you need json, just use json, not text


        # for example
        if data['username'] == 'exampleUser':
            return True
        return False
    except Exception as e:
        print(e)
        pass
    # if get Exception return False
    return False



def write_to_good(text):
    with open('goods.txt', 'a') as f:
        f.write(f"{text}\n")

def main():
    with open('xxx.txt', 'r') as f:
        for i in f:
            # "i" is a one line from file
            param = i.strip()  # remove end-line symbol (EOL)

            # make something
            result = my_checker(param)

            # if check passed, write to 'good' file
            if result:  # the same result == True
                write_to_good(param)

# entrypoint
if __name__ == '__main__':
    main()
 
I think you're trying to do something like that

Python:
import requests

def my_checker(param):
    print('Start check:' + i)
    try:
        # make your http request here
        url = 'https://xxx.com/' + param
        resp = requests.get(url)
        data = resp.json()   # if you need json, just use json, not text


        # for example
        if data['username'] == 'exampleUser':
            return True
        return False
    except Exception as e:
        print(e)
        pass
    # if get Exception return False
    return False



def write_to_good(text):
    with open('goods.txt', 'a') as f:
        f.write(f"{text}\n")

def main():
    with open('xxx.txt', 'r') as f:
        for i in f:
            # "i" is a one line from file
            param = i.strip()  # remove end-line symbol (EOL)

            # make something
            result = my_checker(param)

            # if check passed, write to 'good' file
            if result:  # the same result == True
                write_to_good(param)

# entrypoint
if __name__ == '__main__':
    main()
thank you friend
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх