Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FANBOX download enhancement #680

Merged
merged 23 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b070442
Merge pull request #1 from Nandaka/master
bluerthanever Apr 27, 2020
5f388ee
Modification and implementation for downloading FANBOX post
bluerthanever Apr 27, 2020
90d64ce
Fanbox post records enhancement
bluerthanever Apr 27, 2020
9e33815
Some properties and methods changes
bluerthanever Apr 27, 2020
0ad0dba
Fanbox post download enhancement
bluerthanever Apr 27, 2020
cc784ad
Fixed some indent errors
bluerthanever Apr 27, 2020
2a3a75c
Some logical correction to `insertPost`
bluerthanever Apr 27, 2020
90a82de
Moved codes position
bluerthanever Apr 27, 2020
c792023
Added sep for `exportFanboxPosts`
bluerthanever Apr 27, 2020
3b1387d
Added method to get followed artists
bluerthanever Apr 27, 2020
ac8abf1
Added method for downloading from following artists
bluerthanever Apr 27, 2020
09d6041
Forgot about menu
bluerthanever Apr 27, 2020
39cb68c
Typo. crap....
bluerthanever Apr 27, 2020
fe1e2ec
Big changes..... whew
bluerthanever Apr 28, 2020
ef80c8d
Some big changes
bluerthanever Apr 28, 2020
a92cb5f
Big changes
bluerthanever Apr 28, 2020
52d761a
New option added
bluerthanever Apr 28, 2020
38df85d
Added codes to check FANBOX login status in main()
bluerthanever Apr 28, 2020
1f0a395
Minor change to enable creatorId passed as args
bluerthanever Apr 28, 2020
26f39f5
Put request inside try except inside `fanboxLoginUsingCookie`
bluerthanever Apr 28, 2020
41af87c
Some print and indent correction?
bluerthanever Apr 28, 2020
1d83375
Changes to fit changes to classes in order to pass unit test
bluerthanever Apr 28, 2020
05456ea
Added `creatorId` for the unit test
bluerthanever Apr 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 194 additions & 89 deletions PixivBrowserFactory.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PixivConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class PixivConfig():
ConfigItem("Authentication", "username", ""),
ConfigItem("Authentication", "password", ""),
ConfigItem("Authentication", "cookie", ""),
ConfigItem("Authentication", "cookieFanbox", ""),
ConfigItem("Authentication", "refresh_token", ""),

ConfigItem("Pixiv", "numberOfPage", 0),
Expand Down
134 changes: 132 additions & 2 deletions PixivDBManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,20 @@ def createDatabase(self):
PRIMARY KEY (image_id, page)
)''')
self.conn.commit()


# just to keep track of posts, not to record the details, so no columns like saved_to or caption or whatsoever
c.execute('''CREATE TABLE IF NOT EXISTS fanbox_master_post (
member_id INTEGER,
post_id INTEGER PRIMARY KEY ON CONFLICT IGNORE,
title TEXT,
fee_required INTEGER,
published_date DATE,
updated_date DATE,
post_type TEXT,
last_update_date DATE
)''')
self.conn.commit()

print('done.')
except BaseException:
print('Error at createDatabase():', str(sys.exc_info()))
Expand All @@ -102,6 +115,13 @@ def dropDatabase(self):

c.execute('''DROP TABLE IF EXISTS pixiv_master_image''')
self.conn.commit()

c.execute('''DROP TABLE IF EXISTS pixiv_manga_image''')
self.conn.commit()

c.execute('''DROP TABLE IF EXISTS fanbox_master_post''')
self.conn.commit()

except BaseException:
print('Error at dropDatabase():', str(sys.exc_info()))
print('failed.')
Expand Down Expand Up @@ -211,6 +231,34 @@ def exportDetailedList(self, filename):
c.close()
print('done.')

def exportFanboxPostList(self, filename, sep=","):
print('Exporting FANBOX post list...', end=' ')
try:
c = self.conn.cursor()
c.execute('''SELECT * FROM fanbox_master_post
ORDER BY member_id, post_id''')
filename = filename + '.csv'
writer = codecs.open(filename, 'wb', encoding='utf-8')
columns = ['member_id','post_id','title','fee_required','published_date','update_date','post_type','last_update_date']
writer.write(sep.join(columns))
writer.write('\r\n')
for row in c:
for string in row:
# Unicode write!!
data = str(string)
writer.write(data)
writer.write(sep)
writer.write('\r\n')
writer.write('###END-OF-FILE###')
writer.close()
except BaseException:
print('Error at exportFanboxPostList(): ' + str(sys.exc_info()))
print('failed')
raise
finally:
c.close()
print('done.')

##########################################
# III. Print DB #
##########################################
Expand Down Expand Up @@ -519,6 +567,73 @@ def insertMangaImages(self, manga_files):
finally:
c.close()

def insertPost(self, member_id, post_id, title, fee_required, published_date, post_type):
try:
c = self.conn.cursor()
post_id = int(post_id)
c.execute(
'''INSERT OR IGNORE INTO fanbox_master_post (member_id, post_id) VALUES(?, ?)''',
(member_id, post_id))
c.execute(
'''UPDATE fanbox_master_post SET title = ?, fee_required = ?, published_date = ?,
post_type = ?, last_update_date = datetime('now') WHERE post_id = ?''',
(title, fee_required, published_date, post_type, post_id))
self.conn.commit()
except BaseException:
print('Error at insertPost():', str(sys.exc_info()))
print('failed')
raise
finally:
c.close()

def selectPostByPostId(self, post_id):
try:
c = self.conn.cursor()
post_id = int(post_id)
c.execute(
'''SELECT * FROM fanbox_master_post WHERE post_id = ?''',
(post_id,))
return c.fetchone()
except BaseException:
print('Error at selectPostByPostId():', str(sys.exc_info()))
print('failed')
raise
finally:
c.close()

def updatePostLastUpdateDate(self, post_id, updated_date):
try:
c = self.conn.cursor()
post_id = int(post_id)
c.execute(
'''UPDATE fanbox_master_post SET updated_date = ?
WHERE post_id = ?''',
(updated_date, post_id))
self.conn.commit()
except BaseException:
print('Error at updatePostLastUpdateDate():', str(sys.exc_info()))
print('failed')
raise
finally:
c.close()

def deleteFanboxPost(self, id, by):
id = int(id)
if by not in ["member_id", "post_id"]:
return
sql = f'''DELETE FROM fanbox_master_post WHERE {by} = ?'''

try:
c = self.conn.cursor()
c.execute(sql, (id,))
self.conn.commit()
except BaseException:
print('Error at deleteFanboxPost():', str(sys.exc_info()))
print('failed')
raise
finally:
c.close()

def blacklistImage(self, memberId, ImageId):
try:
c = self.conn.cursor()
Expand Down Expand Up @@ -775,12 +890,16 @@ def menu(self):
print('12. Blacklist image by image_id')
print('13. Show all deleted member')
print('===============================================')
print('f1. Export FANBOX post list')
print('f2. Delete FANBOX download history by post_id')
print('f3. Delete FANBOX download history by member_id')
print('===============================================')
print('c. Clean Up Database')
print('i. Interactive Clean Up Database')
print('p. Compact Database')
print('r. Replace Root Path')
print('x. Exit')
selection = input('Select one?').rstrip("\r")
selection = input('Select one? ').rstrip("\r")
return selection

def main(self):
Expand Down Expand Up @@ -859,6 +978,17 @@ def main(self):
self.blacklistImage(member_id, image_id)
elif selection == '13':
self.printMemberList(isDeleted=True)
elif selection == 'f1':
filename = input('Filename? ').rstrip("\r")
sep = input('Separator? (1(default)=",", 2="\\t") ').rstrip("\r")
sep = "\t" if sep=="2" else ","
self.exportFanboxPostList(filename, sep)
elif selection == 'f2':
member_id = input('member_id? ').rstrip("\r")
self.deleteFanboxPost(member_id, "post_id")
elif selection == 'f3':
post_id = input('post_id? ').rstrip("\r")
self.deleteFanboxPost(post_id, "member_id")
elif selection == 'c':
self.cleanUp()
elif selection == 'i':
Expand Down
Loading