I have a piece of code for a live sub count, which works perfectly, but I wanted to then add those results to a file called 'history.txt', however when I run the code, even if I leave it for quite a while, for the loops to have looped plenty of times, my txt file stays empty.
(code is below) (i KNOW its sloppy don't judge me)
import requests
import time
import os
from time import gmtime, strftime
open("history.txt", "w").close()
histTx = open("history.txt", "a")
def simp():
global histTx
u = input("Input the URL of the channel page:\n")
p = True
while p:
try:
u.index("http")
except ValueError:
u = "http://" + u
response = requests.get(u)
r = str(response.content).lower()
locator = r.index("subscribers")
goBack = locator
while not r[goBack] == "\"":
goBack -= 1
goBack += 1
os.system('clear')
print("\033[1;36;48m", r[goBack : locator].upper())
print("---------\n")
time.sleep(2.5)
os.system('clear')
histTx.write(str(r[goBack : locator].upper()))
def adv():
global histTx
u = input("Input the URL of the channel page (input -1 for simple mode):\n")
if u == "-1":
simp()
else:
p = True
while p:
try:
u.index("http")
except ValueError:
u = "http://" + u
response = requests.get(u)
r = str(response.content).lower()
locator = r.index("subscribers")
goBack = locator
while not r[goBack] == "\"":
goBack -= 1
goBack += 1
os.system('clear')
print("That channel has \033[1;36;48m" + r[goBack : locator].upper() + "\033[0mSubscribers.\n")
print("---------\n")
time.sleep(2.5)
os.system('clear')
histTx.write(str(r[goBack : locator].upper()))
adv()
(Before you ask, no errors, and history.txt does exist.)
The problem is that it should be def simp(histTx)
and def adv(histTx)
, and it should have simp(histTx)
and adv(histTx)
when running it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.