From 634816ff966f886616328ca5f9242bfd731d4b0c Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Mon, 4 May 2020 21:24:13 +0200 Subject: [PATCH 1/2] Do not call sys.exit when the library encounters an error (!) Besides, cleanup some whitespace --- GetOldTweets3/manager/TweetManager.py | 31 +++++++-------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/GetOldTweets3/manager/TweetManager.py b/GetOldTweets3/manager/TweetManager.py index 056c6c2a..8b80b1dd 100644 --- a/GetOldTweets3/manager/TweetManager.py +++ b/GetOldTweets3/manager/TweetManager.py @@ -118,7 +118,7 @@ def getTweets(tweetCriteria, receiveBuffer=None, bufferLength=100, proxy=None, d results.append(tweet) resultsAux.append(tweet) - + if receiveBuffer and len(resultsAux) >= bufferLength: receiveBuffer(resultsAux) resultsAux = [] @@ -134,7 +134,7 @@ def getTweets(tweetCriteria, receiveBuffer=None, bufferLength=100, proxy=None, d return results - @staticmethod + @staticmethod def getHashtagsAndMentions(tweetPQ): """Given a PyQuery instance of a tweet (tweetPQ) getHashtagsAndMentions gets the hashtags and mentions from a tweet using the tweet's @@ -153,7 +153,7 @@ def getHashtagsAndMentions(tweetPQ): continue # Mention anchor tags have a data-mentioned-user-id - # attribute. + # attribute. if not tagPQ.attr("data-mentioned-user-id") is None: mentions.append("@" + url[1:]) continue @@ -219,7 +219,7 @@ def textify(html, emoji): html = match.group(4) attr = TweetManager.parse_attributes(link) - try: + try: if "u-hidden" in attr["class"]: pass elif "data-expanded-url" in attr \ @@ -351,25 +351,10 @@ def getJsonResponse(tweetCriteria, refreshCursor, cookieJar, proxy, useragent=No print(url) print('\n'.join(h[0]+': '+h[1] for h in headers)) - try: - response = opener.open(url) - jsonResponse = response.read() - except Exception as e: - print("An error occured during an HTTP request:", str(e)) - print("Try to open in browser: https://twitter.com/search?q=%s&src=typd" % urllib.parse.quote(urlGetData)) - sys.exit() - - try: - s_json = jsonResponse.decode() - except: - print("Invalid response from Twitter") - sys.exit() - - try: - dataJson = json.loads(s_json) - except: - print("Error parsing JSON: %s" % s_json) - sys.exit() + response = opener.open(url) + jsonResponse = response.read() + s_json = jsonResponse.decode() + dataJson = json.loads(s_json) if debug: print(s_json) From bf7a2f3bddff12efbb8a7e9b1203b0668900a7df Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Mon, 4 May 2020 21:31:53 +0200 Subject: [PATCH 2/2] Bump the version --- GetOldTweets3/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GetOldTweets3/__init__.py b/GetOldTweets3/__init__.py index e0496b3a..2eb8708e 100644 --- a/GetOldTweets3/__init__.py +++ b/GetOldTweets3/__init__.py @@ -1,4 +1,4 @@ from . import models from . import manager -__version__ = '0.0.11' +__version__ = '0.0.12' diff --git a/setup.py b/setup.py index 620fcf21..0f84b8ef 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name="GetOldTweets3", - version="0.0.11", + version="0.0.12", author="Dmitry Mottl", author_email="dmitry.mottl@gmail.com", license='MIT',