File tree Expand file tree Collapse file tree 9 files changed +78
-0
lines changed Expand file tree Collapse file tree 9 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ /AppStorage /
Original file line number Diff line number Diff line change
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" ]
Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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 " )
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments