Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
renamed mainWindow to main so that pyinstaller doesn't make problems.
removed the settings file, they weren't even settings, they were just random Sankaku constants in a file
  • Loading branch information
fcdev committed May 26, 2021
1 parent bf48a11 commit bb7678f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 15 additions & 7 deletions Sankaku.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import requests
import mimetypes
import json
import Settings

# region Sankaku stuff
API_URL = "https://capi-v2.sankakucomplex.com/"
HTTP_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'}

POST_ID = "id"
POST_URL = "file_url"
POST_MIME = "file_type"
# endregion

class Sankaku:
__session = requests.Session()
Expand All @@ -22,10 +30,10 @@ def __getFileType(url):

@staticmethod
def download_post(post, folder):
if(post[Settings.POST_URL] == None):
if(post[POST_URL] == None):
print(f"Can't download: {post}")
r = Sankaku.__session.get(post[Settings.POST_URL])
open(folder+"\\"+str(post[Settings.POST_ID]) + Sankaku.__getFileType(post[Settings.POST_URL]), 'wb').write(r.content)
r = Sankaku.__session.get(post[POST_URL])
open(folder+"\\"+str(post[POST_ID]) + Sankaku.__getFileType(post[POST_URL]), 'wb').write(r.content)
#endregion

def get_posts(self):
Expand All @@ -47,7 +55,7 @@ def _getPage(self, page = None):
}
if (page != None):
params['next'] = page
return json.loads(Sankaku.__session.get(Settings.API_URL + 'posts/keyset', params = params).content)
return json.loads(Sankaku.__session.get(API_URL + 'posts/keyset', params = params).content)


def __init__(self,tags,folder,print = None):
Expand All @@ -59,12 +67,12 @@ def output(self, string):
if(callable(self.print)): self.print(string)

def download(self):
Sankaku.__session.headers['User-Agent'] = Settings.HTTP_HEADERS['User-Agent']
Sankaku.__session.headers['User-Agent'] = HTTP_HEADERS['User-Agent']
self.progress = 0
posts = self.get_posts()
self.total = len(posts)
for i in range(self.total):
self.output("D("+str(i+1)+"/"+str(self.total)+"):"+ str(posts[i][Settings.POST_ID]))
self.output("D("+str(i+1)+"/"+str(self.total)+"):"+ str(posts[i][POST_ID]))
Sankaku.download_post(posts[i],self.folder)
self.progress += 1
self.output("Complete")
6 changes: 0 additions & 6 deletions Settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
API_URL = "https://capi-v2.sankakucomplex.com/"
HTTP_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'}

POST_ID = "id"
POST_URL = "file_url"
POST_MIME = "file_type"
File renamed without changes.

0 comments on commit bb7678f

Please sign in to comment.