MtDu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300802

Change subject: Convert panoramiopicker.py to requests
......................................................................

Convert panoramiopicker.py to requests

Bug: T130522
Change-Id: If73276b61433831ef6edcd768b6d7c64d7db847f
---
M scripts/panoramiopicker.py
1 file changed, 7 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/02/300802/1

diff --git a/scripts/panoramiopicker.py b/scripts/panoramiopicker.py
index a971687..f15485a 100644
--- a/scripts/panoramiopicker.py
+++ b/scripts/panoramiopicker.py
@@ -15,6 +15,7 @@
 import hashlib
 import json
 import re
+import requests
 import socket
 import StringIO
 
@@ -27,11 +28,6 @@
 from pywikibot.tools import PY2
 
 from scripts import imagerecat, upload
-
-if not PY2:
-    from urllib.request import urlopen
-else:
-    from urllib import urlopen
 
 try:
     from pywikibot.userinterfaces.gui import Tkdialog
@@ -57,7 +53,7 @@
     TODO: Add exception handling
 
     """
-    imageFile = urlopen(photoUrl).read()
+    imageFile = requests.get(photoUrl).content
     return StringIO.StringIO(imageFile)
 
 
@@ -81,8 +77,8 @@
 def getLicense(photoInfo):
     """Adding license to the Panoramio API with a beautiful soup hack."""
     photoInfo['license'] = u'c'
-    page = urlopen(photoInfo.get(u'photo_url'))
-    data = page.read()
+    page = requests.get(photoInfo.get(u'photo_url'))
+    data = page.content
     soup = BeautifulSoup(data)
     if soup.find("div", {'id': 'photo-info'}):
         pointer = soup.find("div", {'id': 'photo-info'})
@@ -266,8 +262,9 @@
             try:
                 if tries < maxtries:
                     tries += 1
-                    panoramioApiPage = urlopen(url % (photoset, i, i + 
interval))
-                    contents = panoramioApiPage.read().decode('utf-8')
+                    panoramioApiPage = requests.get(url % (photoset, i, i + 
interval))
+                    panoramioApiPage.decoding = 'utf-8'
+                    contents = panoramioApiPage.text
                     gotInfo = True
                     i += interval
                 else:

-- 
To view, visit https://gerrit.wikimedia.org/r/300802
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If73276b61433831ef6edcd768b6d7c64d7db847f
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: MtDu <justin.d...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to