Skip to content

Commit

Permalink
v20150923
Browse files Browse the repository at this point in the history
Externalize date format to config.ini, refer to http://strftime.org/ for
formatting syntax
  • Loading branch information
Nandaka committed Sep 23, 2015
1 parent 032e6a0 commit 5fd321e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
10 changes: 10 additions & 0 deletions PixivConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PixivConfig:
# Pixiv related?
numberOfPage = 0
r18mode = False
dateFormat = None

# generic Settings
filenameFormat = unicode('%artist% (%member_id%)' + os.sep + '%urlFilename% - %title%')
Expand Down Expand Up @@ -399,6 +400,13 @@ def loadConfig(self, path=None):
print "dumpTagSearchPage = False"
haveError = True

try:
self.dateFormat = config.get('Pixiv','dateFormat')
except ValueError:
print "dateFormat = ''"
self.dateFormat = None
haveError = True


## except ConfigParser.NoOptionError:
## print 'Error at loadConfig():',sys.exc_info()
Expand Down Expand Up @@ -485,6 +493,7 @@ def writeConfig(self, error=False, path=None):
config.add_section('Pixiv')
config.set('Pixiv', 'numberOfPage', self.numberOfPage)
config.set('Pixiv', 'R18Mode', self.r18mode)
config.set('Pixiv', 'DateFormat', self.dateFormat)

if path != None:
configlocation = path
Expand Down Expand Up @@ -571,4 +580,5 @@ def printConfig(self):
print ' [Pixiv]'
print ' - numberOfPage =', self.numberOfPage
print ' - R18Mode =', self.r18mode
print ' - DateFormat =', self.dateFormat
print ''
2 changes: 1 addition & 1 deletion PixivConstant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: UTF-8 -*-
# pylint: disable=I0011, C, C0302

PIXIVUTIL_VERSION = '20150725-beta1'
PIXIVUTIL_VERSION = '20150923'
PIXIVUTIL_LINK = 'https://nandaka.wordpress.com/tag/pixiv-downloader/'
PIXIV_URL = 'http://www.pixiv.net'
PIXIV_URL_SSL = 'https://www.secure.pixiv.net/login.php'
Expand Down
27 changes: 19 additions & 8 deletions PixivModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ class PixivImage:
bookmark_count = -1
image_response_count = -1
ugoira_data = ""
dateFormat = None

def __init__(self, iid=0, page=None, parent=None, fromBookmark=False, bookmark_count=-1, image_response_count=-1):
def __init__(self, iid=0, page=None, parent=None, fromBookmark=False, bookmark_count=-1, image_response_count=-1, dateFormat = None):
self.artist = parent
self.fromBookmark = fromBookmark
self.bookmark_count = bookmark_count
self.imageId = iid
self.imageUrls = []
self.dateFormat = dateFormat

if page != None:
## check is error page
Expand Down Expand Up @@ -324,16 +326,25 @@ def ParseWorksData(self, page):
#1/05/2011 07:09|723×1023|Photoshop SAI [ R-18 ]
#2013年3月16日 06:44 | 800×1130 | Photoshop ComicStudio | R-18
#2013年12月14日 19:00 855×1133 PhotoshopSAI
self.worksDate = PixivHelper.toUnicode(temp[0].string, encoding=sys.stdin.encoding).replace(u'/', u'-')
if self.worksDate.find('-') > -1:

self.worksDate = PixivHelper.toUnicode(temp[0].string, encoding=sys.stdin.encoding)
if self.dateFormat is not None and len(self.dateFormat) > 0:
# use the user defined format
try:
self.worksDateDateTime = datetime.strptime(self.worksDate, u'%m-%d-%Y %H:%M')
self.worksDateDateTime = datetime.strptime(self.worksDate, self.dateFormat)
except ValueError as ve:
PixivHelper.GetLogger().exception('Error when parsing datetime: {0} for imageId {1}'.format(self.worksDate, self.imageId), ve)
self.worksDateDateTime = datetime.strptime(self.worksDate.split(" ")[0], u'%Y-%m-%d')
PixivHelper.GetLogger().exception('Error when parsing datetime: {0} for imageId {1} using date format {2}'.format(self.worksDate, self.imageId, self.dateFormat), ve)
else:
tempDate = self.worksDate.replace(u'年', '-').replace(u'月','-').replace(u'日', '')
self.worksDateDateTime = datetime.strptime(tempDate, '%Y-%m-%d %H:%M')
self.worksDate = self.worksDate.replace(u'/', u'-')
if self.worksDate.find('-') > -1:
try:
self.worksDateDateTime = datetime.strptime(self.worksDate, u'%m-%d-%Y %H:%M')
except ValueError as ve:
PixivHelper.GetLogger().exception('Error when parsing datetime: {0} for imageId {1}'.format(self.worksDate, self.imageId), ve)
self.worksDateDateTime = datetime.strptime(self.worksDate.split(" ")[0], u'%Y-%m-%d')
else:
tempDate = self.worksDate.replace(u'年', '-').replace(u'月','-').replace(u'日', '')
self.worksDateDateTime = datetime.strptime(tempDate, '%Y-%m-%d %H:%M')

self.worksResolution = unicode(temp[1].string).replace(u'×',u'x')
toolsTemp = page.find(attrs={'class':'meta'}).find(attrs={'class':'tools'})
Expand Down
4 changes: 2 additions & 2 deletions PixivUtil2.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def process_image(mode, artist=None, image_id=None, user_dir='', bookmark=False,
## get the medium page
try:
parse_medium_page = PixivBrowserFactory.getBrowser().getPixivPage(referer)
image = PixivImage(iid=image_id, page=parse_medium_page, parent=artist, fromBookmark=bookmark, bookmark_count=bookmark_count)
image = PixivImage(iid=image_id, page=parse_medium_page, parent=artist, fromBookmark=bookmark, bookmark_count=bookmark_count, dateFormat=__config__.dateFormat)
if image.imageMode == "ugoira_view" or image.imageMode == "bigNew":
image.ParseImages(page=parse_medium_page)
if title_prefix is not None:
Expand Down Expand Up @@ -787,7 +787,7 @@ def process_tags(mode, tags, page=1, end_page=0, wild_card=True, title_caption=F
# get the last date
referer = 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=' + str(last_image_id)
parse_medium_page = PixivBrowserFactory.getBrowser().getPixivPage(referer)
image = PixivImage(iid=last_image_id, page=parse_medium_page)
image = PixivImage(iid=last_image_id, page=parse_medium_page, dateFormat=__config__.dateFormat)
_last_date = image.worksDateDateTime.strftime("%Y-%m-%d")
# hit the last page
PixivHelper.printAndLog('info', "Hit page 1000, looping back to page 1 with ecd: " + str(_last_date))
Expand Down
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
20150725-beta1:
20150923:
- Fix Issue #88: undefined variable when handling cookie.
- Externalize date format to config.ini, refer to http://strftime.org/ for formatting syntax

20150715:
- Fix Issue #87: Update login logic, now always use https.
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,13 @@ keepsignedin ==> Set to 1 to tick the keep signed in check box on login form.
[Pixiv]
numberofpage ==> Number of page to be processed, put '0' to process all pages.
r18mode ==> Only list images tagged R18, for member, member's bookmark,
and search by tag.
Set to 'True' to apply.
and search by tag. Set to 'True' to apply.
dateformat ==> Pixiv DateTime format, leave blank to use default format for
English or Japanese. Refer to http://strftime.org/ for syntax.
Quick Reference:
%d = Day, %m = Month, %Y = Year (4 digit), %H = Hour (24h)
%M = Minute, %S = Seconds

[Network]
useproxy ==> Set 'True' to use proxy server, 'False' to disable it.
proxyaddress ==> Proxy server address, use this format:
Expand Down

0 comments on commit 5fd321e

Please sign in to comment.