Added Self class

This commit is contained in:
Ali Parlakci
2018-07-10 01:30:50 +03:00
parent e3a97cc495
commit 4e8e59f527
3 changed files with 81 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
import io
import os
import sys
import urllib.request
@@ -16,7 +17,7 @@ except ModuleNotFoundError:
install("imgurpython")
from imgurpython import *
VanillaPrint = print
print = printToFile
def dlProgress(count, blockSize, totalSize):
@@ -233,8 +234,13 @@ class Gfycat:
fileDir = directory / (title+"_"+POST['postId']+POST['postExt'])
tempDir = directory / (title+"_"+POST['postId']+".tmp")
try:
getFile(fileDir,tempDir,POST['mediaURL'])
except FileNameTooLong:
fileDir = directory / (POST['postId']+POST['postExt'])
tempDir = directory / (POST['postId']+".tmp")
getFile(fileDir,tempDir,POST['mediaURL'])
getFile(fileDir,tempDir,POST['mediaURL'])
def getLink(self, url, query='<source id="mp4Source" src=', lineNumber=105):
"""Extract direct link to the video from page's source
@@ -282,4 +288,46 @@ class Direct:
tempDir = title+"_"+POST['postId']+".tmp"
tempDir = directory / tempDir
getFile(fileDir,tempDir,POST['postURL'])
try:
getFile(fileDir,tempDir,POST['postURL'])
except FileNameTooLong:
fileDir = directory / (POST['postId']+POST['postExt'])
tempDir = directory / (POST['postId']+".tmp")
getFile(fileDir,tempDir,POST['postURL'])
class Self:
def __init__(self,directory,post):
if not os.path.exists(directory): os.makedirs(directory)
title = nameCorrector(post['postTitle'])
print(title+"_"+post['postId']+".md")
fileDir = title+"_"+post['postId']+".md"
fileDir = directory / fileDir
if Path.is_file(fileDir):
raise FileAlreadyExistsError
self.writeToFile(fileDir,post)
@staticmethod
def writeToFile(directory,post):
content = ("## ["
+ post["postTitle"]
+ "]("
+ post["postURL"]
+ ")\n"
+ post["postContent"]
+ "\n\n---\n\n"
+ "submitted by [u/"
+ post["postSubmitter"]
+ "](https://www.reddit.com/user/"
+ post["postSubmitter"]
+ ")")
with io.open(directory,"w",encoding="utf-8") as FILE:
VanillaPrint(content,file=FILE)
print("Downloaded")