Skip to content

Commit 861b6b5

Browse files
committed
initial commit
0 parents  commit 861b6b5

File tree

9 files changed

+78
-0
lines changed

9 files changed

+78
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/AppStorage/

LinkExtractor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# In this file, I will handle extraction processes.
2+
# Just only one line will considered.
3+
# Separation thing should be on main.py I guess.
4+
# Example Log Line: 2024-01-28 00:06:04|vidshar.org|https://cdn2.vadsr.shop/maxz38snwlzv.html||[YuushaSubs] Puzzle and Dragons Cross - 09.mp4|
5+
6+
def Extract(line: str):
7+
# First Line: Upload Date
8+
# Second Line: Server Domain
9+
# Third Line: URL
10+
# Fourth Line: File Name
11+
# I will just use third and fourth line.
12+
13+
try:
14+
url = line.split("|")[2]
15+
fileName = line.split("|")[4]
16+
return [url, fileName]
17+
except:
18+
print("Wrong log line encountered: {}".format(line))
19+
return ["null", "null"]

Remover.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
3+
def CheckLinksFile():
4+
isExists = os.path.exists("links.txt")
5+
6+
if (not isExists):
7+
print("Your links.txt file is not exists. New one created.")
8+
file = open("links.txt", "x")
9+
10+
def RemoveLines():
11+
file = open("links.txt", "w")
12+
file.write("") # Now entire file content erased.

Saver.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# In this file, I will handle writing processes.
2+
# My aim is write each file on different text files.
3+
# Input is going to be [url, fileName]
4+
5+
import os
6+
7+
def CheckFile(fileName):
8+
path = "AppStorage/" + fileName + ".txt"
9+
isExists = os.path.exists(path)
10+
11+
if (not isExists):
12+
open((path), "x")
13+
14+
def CheckFolder():
15+
# In this function, I will handle folder existence.
16+
# If folder not exists, function gonna be create new folder.
17+
18+
isExists = os.path.exists("AppStorage")
19+
20+
if (not isExists):
21+
os.mkdir("AppStorage")
22+
23+
def WriteData(Data):
24+
# Data -> [URL, fileName]
25+
path = "AppStorage/" + Data[1] + ".txt"
26+
CheckFolder() # Ensure the folder exists
27+
CheckFile(Data[1]) # Ensure the file exists
28+
29+
with open(path, "a") as file:
30+
file.write(Data[0] + "\n")
739 Bytes
Binary file not shown.

__pycache__/Remover.cpython-311.pyc

883 Bytes
Binary file not shown.

__pycache__/Saver.cpython-311.pyc

1.48 KB
Binary file not shown.

main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from LinkExtractor import Extract
2+
from Saver import CheckFolder, WriteData
3+
from Remover import CheckLinksFile, RemoveLines
4+
5+
def main():
6+
CheckLinksFile()
7+
fileData = open("links.txt", "r").readlines()
8+
CheckFolder()
9+
10+
for x in fileData:
11+
data = Extract(x)
12+
WriteData(data)
13+
14+
RemoveLines()
15+
16+
main()

0 commit comments

Comments
 (0)