Modular
This commit is contained in:
parent
95edbc3c0b
commit
f755fafe4d
|
@ -0,0 +1 @@
|
|||
__pycache__/
|
61
URLs.py
61
URLs.py
|
@ -1,24 +1,41 @@
|
|||
import subprocess, json, random, sys
|
||||
|
||||
url = ""
|
||||
try:
|
||||
with open("file.json") as file:
|
||||
urls = json.load(file)
|
||||
except Exception:
|
||||
urls = {}
|
||||
for i in range(0,random.randint(1,10)):
|
||||
url += chr(random.choice((random.randint(65,90), random.randint(97,122), random.randint(48,57)))) #first one: uppercase; second one: lowercase; third one: numebes
|
||||
print("Pinging URL %s"%url)
|
||||
j=subprocess.Popen([("""curl -w "%%{url_effective}\n" -I -L -s -S tiny.cc/%s -o /dev/null"""%url)], shell=True, executable="/bin/bash", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stuff=j.communicate()
|
||||
if j.returncode != 0:
|
||||
print("Failed; exiting.")
|
||||
sys.exit(1)
|
||||
print(stuff)
|
||||
urls[url] = stuff[0].decode("utf-8").replace("\n","")
|
||||
if urls[url] == f"tiny.cc/{url}" or urls[url] == f"https://tiny.cc/{url}" or urls[url] == f"http://tiny.cc/{url}":
|
||||
print("Nonexistent URL")
|
||||
sys.exit(2)
|
||||
del urls[url]
|
||||
with open("file.json","w+") as file:
|
||||
file.write(json.dumps(urls))
|
||||
class DownloadError(RuntimeError):
|
||||
pass
|
||||
class NonexistentUrl(BaseException):
|
||||
pass
|
||||
class URL:
|
||||
def __init__(self):
|
||||
self.GetConfig()
|
||||
def GetURL(self, urlRange=(1,10)):
|
||||
self.url = ""
|
||||
for i in range(0,random.randint(*urlRange)):
|
||||
self.url += chr(random.choice((random.randint(65,90), random.randint(97,122), random.randint(48,57)))) #first one is uppercase; 2nd is lowercase; 3rd: numbers
|
||||
def GetConfig(self):
|
||||
try:
|
||||
with open("file.json") as file:
|
||||
self.urls = json.load(file)
|
||||
except Exception:
|
||||
self.urls = {}
|
||||
def GetDownload(self):
|
||||
print(f"Pinging URL {self.url}")
|
||||
self.j = subprocess.Popen(["""curl -w "%%{url_effective}" -I -L -s -S tiny.cc/%s -o /dev/null"""%self.url], shell=True, executable="/bin/bash", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
self.output = self.j.communicate()
|
||||
if self.j.returncode != 0:
|
||||
raise DownloadError(self.output)
|
||||
GetResult = GetDownload
|
||||
def WriteFile(self):
|
||||
self.urls[self.url] = self.output[0].decode("utf-8")
|
||||
if self.urls[self.url] == f"tiny.cc/{self.url}" or self.urls[self.url] == f"https://tiny.cc/{self.url}" or self.urls[self.url] == f"http://tiny.cc/{self.url}":
|
||||
raise NonexistentUrl(self.url)
|
||||
with open("file.json","w+") as file:
|
||||
file.write(json.dumps(self.urls))
|
||||
|
||||
def main():
|
||||
datums = URL()
|
||||
datums.GetURL()
|
||||
datums.GetDownload()
|
||||
datums.WriteFile()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import subprocess, URLs
|
||||
print("Infinitely running the file. (To stop this, add a file called \"sotp\" in the working directory.)")
|
||||
while True:
|
||||
try:
|
||||
open("sotp")
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
print("sotpping")
|
||||
sys.exit(0)
|
||||
try:
|
||||
URLs.main()
|
||||
except URLs.NonexistentUrl as ename:
|
||||
print("NonexistentUrl - %s"%ename)
|
||||
except Exception as ename:
|
||||
print(f"Error - {ename}")
|
Loading…
Reference in New Issue