From 4d6e430360122d2b904cd299adc7898530acd969 Mon Sep 17 00:00:00 2001 From: grtfou Date: Tue, 30 Dec 2014 16:37:52 +0800 Subject: [PATCH] Enhance: Support python 3 --- .travis.yml | 7 +++++++ gplus_crawler.py | 7 ++++--- tests/test_main.py | 15 ++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2497131..5b635c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,14 @@ language: python python: + - "2.6" - "2.7" + - "3.0" + - "3.1" + - "3.2" + - "3.3" + - "3.4" + - "3.5" # command to install dependencies before_install: - sudo apt-get update -qq diff --git a/gplus_crawler.py b/gplus_crawler.py index 59e24d1..393d095 100644 --- a/gplus_crawler.py +++ b/gplus_crawler.py @@ -1,14 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # @first_date 20130414 -# @date 20141230 - Fix: Certification on HTTPS connection +# @date 20141230 - Fix: Certification on HTTPS connection and support py3 """ Download photo or videos from google plus """ from __future__ import unicode_literals from __future__ import print_function -from __future__ import division import os import re @@ -173,7 +172,9 @@ def _get_url_context(self, uid, d_type): if date_list and video_list and line == ']': filename = "{}.mp4".format(date_list.group(1).replace('/', '-')) - video_url = video_list.group(1).replace(b'\u003d', b'=').replace(b'\u0026', b'&') + video_url = (video_list.group(1).encode('utf-8') + .replace(b'\u003d', b'=').replace(b'\u0026', b'&')) + print(filename) filename = '{0}{1}video{1}{2}'.format(uid, os.sep, filename) diff --git a/tests/test_main.py b/tests/test_main.py index afe07aa..218876c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,14 +1,18 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # @first_date 20140916 -# @date 20141117 - Edit to unit test format -''' +# @date 20141230 - Added tearDown function +""" Test main function for download image -''' +""" import unittest -import sys, os +import sys +import os +import shutil + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + from gplus_crawler import GplusCrawler class TestMainFunction(unittest.TestCase): @@ -16,7 +20,8 @@ def setUp(self): self.user_id = '115975634910643785199' def tearDown(self): - self.user_id = None + if os.path.exists(self.user_id): + shutil.rmtree(self.user_id) def test_video(self): main_program = GplusCrawler()