Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Do not call sys.exit when the library encounters an error (!) #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GetOldTweets3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import models
from . import manager

__version__ = '0.0.11'
__version__ = '0.0.12'
31 changes: 8 additions & 23 deletions GetOldTweets3/manager/TweetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name="GetOldTweets3",
version="0.0.11",
version="0.0.12",
author="Dmitry Mottl",
author_email="[email protected]",
license='MIT',
Expand Down