Skip to content

Commit

Permalink
Feature/python3 print format (#328)
Browse files Browse the repository at this point in the history
* chg: dev: use python3 print format

* chg: dev: use future lib

* chg: dev: print line with trailing comma

* chg: dev: missing parenthesis

* fix: dev: miss end kwarg
  • Loading branch information
rachmadaniHaryono authored and Nandaka committed Feb 26, 2018
1 parent e3fd9e7 commit 3f0d163
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 549 deletions.
77 changes: 39 additions & 38 deletions PixivBrowserFactory.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# pylint: disable=I0011, C, C0302
from __future__ import print_function

import mechanize
from BeautifulSoup import BeautifulSoup
Expand Down Expand Up @@ -126,9 +127,9 @@ def getPixivPage(self, url, referer="https://www.pixiv.net", returnParsed=True):

if retry_count < self._config.retry:
for t in range(1, self._config.retryWait):
print t,
print(t, end = ' ')
time.sleep(1)
print ''
print('')
retry_count = retry_count + 1
else:
raise PixivException("Failed to get page: " + ex.message, errorCode=PixivException.SERVER_ERROR)
Expand Down Expand Up @@ -255,13 +256,13 @@ def getMyId(self, parsed):

def detectWhiteCube(self, page, url):
if url.find("pixiv.net/whitecube") > 0:
print "*******************************************"
print "* Pixiv whitecube UI mode. *"
print "* Some feature might not working properly *"
print "*******************************************"
print("*******************************************")
print("* Pixiv whitecube UI mode. *")
print("* Some feature might not working properly *")
print("*******************************************")
js_init = self._getInitConfig(page)
self._whitecubeToken = js_init["pixiv.context.token"]
print "whitecube token:", self._whitecubeToken
print("whitecube token:", self._whitecubeToken)
self._isWhitecube = True

def parseLoginError(self, res):
Expand Down Expand Up @@ -544,7 +545,7 @@ def test():

if success:
def testSearchTags():
print "test search tags"
print("test search tags")
tags = "VOCALOID"
p = 1
wild_card = True
Expand All @@ -566,75 +567,75 @@ def testSearchTags():
assert(len(resultS.itemList) > 0)

def testImage():
print "test image mode"
print ">>"
print("test image mode")
print(">>")
(result, page) = b.getImagePage(60040975)
print result.PrintInfo()
print(result.PrintInfo())
assert(len(result.imageTitle) > 0)
print result.artist.PrintInfo()
print(result.artist.PrintInfo())
assert(len(result.artist.artistToken) > 0)
assert(not("R-18" in result.imageTags))
assert(result.worksTools.find("CLIP STUDIO PAINT") > -1)

print ">>"
print(">>")
(result2, page2) = b.getImagePage(59628358)
print result2.PrintInfo()
print(result2.PrintInfo())
assert(len(result2.imageTitle) > 0)
print result2.artist.PrintInfo()
print(result2.artist.PrintInfo())
assert(len(result2.artist.artistToken) > 0)
assert("R-18" in result2.imageTags)

print ">> ugoira"
print(">> ugoira")
(result3, page3) = b.getImagePage(60070169)
print result3.PrintInfo()
print(result3.PrintInfo())
assert(len(result3.imageTitle) > 0)
print result3.artist.PrintInfo()
print result3.ugoira_data
print(result3.artist.PrintInfo())
print(result3.ugoira_data)
assert(len(result3.artist.artistToken) > 0)
assert(result3.imageMode == 'ugoira_view')

def testMember():
print "Test member mode"
print ">>"
print("Test member mode")
print(">>")
(result3, page3) = b.getMemberPage(1227869, page=1, bookmark=False, tags=None)
print result3.PrintInfo()
print(result3.PrintInfo())
assert(len(result3.artistToken) > 0)
assert(len(result3.imageList) > 0)
print ">>"
print(">>")
(result4, page4) = b.getMemberPage(1227869, page=2, bookmark=False, tags=None)
print result4.PrintInfo()
print(result4.PrintInfo())
assert(len(result4.artistToken) > 0)
assert(len(result4.imageList) > 0)
print ">>"
print(">>")
(result5, page5) = b.getMemberPage(4894, page=1, bookmark=False, tags=None)
print result5.PrintInfo()
print(result5.PrintInfo())
assert(len(result5.artistToken) > 0)
assert(len(result5.imageList) > 0)
print ">>"
print(">>")
(result6, page6) = b.getMemberPage(4894, page=3, bookmark=False, tags=None)
print result6.PrintInfo()
print(result6.PrintInfo())
assert(len(result6.artistToken) > 0)
assert(len(result6.imageList) > 0)

def testMemberBookmark():
print "Test member bookmarks mode"
print ">>"
print("Test member bookmarks mode")
print(">>")
(result5, page5) = b.getMemberPage(1227869, page=1, bookmark=True, tags=None)
print result5.PrintInfo()
print(result5.PrintInfo())
assert(len(result5.artistToken) > 0)
assert(len(result5.imageList) > 0)
print ">>"
print(">>")
(result6, page6) = b.getMemberPage(1227869, page=2, bookmark=True, tags=None)
print result6.PrintInfo()
print(result6.PrintInfo())
assert(len(result6.artistToken) > 0)
assert(len(result6.imageList) > 0)
print ">>"
print(">>")
(result6, page6) = b.getMemberPage(1227869, page=10, bookmark=True, tags=None)
if result6 is not None:
print result6.PrintInfo()
print(result6.PrintInfo())
(result6, page6) = b.getMemberPage(1227869, page=12, bookmark=True, tags=None)
if result6 is not None:
print result6.PrintInfo()
print(result6.PrintInfo())
assert(len(result6.artistToken) > 0)
assert(len(result6.imageList) == 0)

Expand All @@ -644,9 +645,9 @@ def testMemberBookmark():
# testMemberBookmark()

else:
print "Invalid username or password"
print("Invalid username or password")


if __name__ == '__main__':
test()
print "done"
print("done")

3 comments on commit 3f0d163

@momoe
Copy link

@momoe momoe commented on 3f0d163 Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of an effort to migrate PixivUtil to python3 support?

@Nandaka
Copy link
Owner

@Nandaka Nandaka commented on 3f0d163 Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I don't plan to move it to py3 yet. I think @rachmadaniHaryono plan to call the script from his own py.

I'm still using py2.7

@rachmadaniHaryono
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@momoe see #190 I have an experimental branch on my fork for python3 support.

Please sign in to comment.