python3 support

This commit is contained in:
ricterz 2015-05-23 15:51:18 +08:00
parent ff7d566aae
commit b85af08ca0
3 changed files with 20 additions and 14 deletions

View File

@ -1,16 +1,20 @@
#coding: utf-8 #coding: utf-8
from __future__ import print_function
from optparse import OptionParser from optparse import OptionParser
from itertools import ifilter
from logger import logger from logger import logger
try:
from itertools import ifilter as filter
except ImportError:
pass
def banner(): def banner():
print ''' _ _ _ _ print(''' _ _ _ _
_ __ | | | | ___ _ __ | |_ __ _(_) _ __ | | | | ___ _ __ | |_ __ _(_)
| '_ \| |_| |/ _ \ '_ \| __/ _` | | | '_ \| |_| |/ _ \ '_ \| __/ _` | |
| | | | _ | __/ | | | || (_| | | | | | | _ | __/ | | | || (_| | |
|_| |_|_| |_|\___|_| |_|\__\__,_|_| |_| |_|_| |_|\___|_| |_|\__\__,_|_|
''' ''')
def cmd_parser(): def cmd_parser():
@ -31,7 +35,7 @@ def cmd_parser():
if args.ids: if args.ids:
_ = map(lambda id: id.strip(), args.ids.split(',')) _ = map(lambda id: id.strip(), args.ids.split(','))
args.ids = set(map(int, ifilter(lambda id: id.isdigit(), _))) args.ids = set(map(int, filter(lambda id: id.isdigit(), _)))
if args.is_download and not args.id and not args.ids and not args.keyword: if args.is_download and not args.id and not args.ids and not args.keyword:
logger.critical('Dojinshi id/ids is required for downloading') logger.critical('Dojinshi id/ids is required for downloading')

View File

@ -1,3 +1,4 @@
from __future__ import print_function
from constant import DETAIL_URL, IMAGE_URL from constant import DETAIL_URL, IMAGE_URL
from logger import logger from logger import logger
@ -18,10 +19,10 @@ class Dojinshi(object):
def show(self): def show(self):
logger.info('Print dojinshi information') logger.info('Print dojinshi information')
print 'Dojinshi: %s' % self.name print('Dojinshi: %s' % self.name)
print 'Subtitle: %s' % self.subtitle print('Subtitle: %s' % self.subtitle)
print 'URL: %s' % self.url print('URL: %s' % self.url)
print 'Pages: %d' % self.pages print('Pages: %d' % self.pages)
def download(self): def download(self):
logger.info('Start download dojinshi: %s' % self.name) logger.info('Start download dojinshi: %s' % self.name)
@ -36,9 +37,9 @@ class Dojinshi(object):
if __name__ == '__main__': if __name__ == '__main__':
test = Dojinshi(name='test nhentai dojinshi', id=1) test = Dojinshi(name='test nhentai dojinshi', id=1)
print test print(test)
test.show() test.show()
try: try:
test.download() test.download()
except Exception as e: except Exception as e:
print 'Exception: %s' % str(e) print('Exception: %s' % str(e))

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import sys import sys
import re import re
import requests import requests
@ -66,11 +67,11 @@ def print_dojinshi(dojinshi_list):
if not dojinshi_list: if not dojinshi_list:
return return
logger.log(15, 'Print dojinshi list') logger.log(15, 'Print dojinshi list')
print '-' * 60 print('-' * 60)
for dojinshi in dojinshi_list: for dojinshi in dojinshi_list:
print dojinshi['id'], '-', dojinshi['title'] print(dojinshi['id'], '-', dojinshi['title'])
print '-' * 60 print('-' * 60)
if __name__ == '__main__': if __name__ == '__main__':
print dojinshi_parser(32271) print(dojinshi_parser(32271))