Changed codebase's syntax before attempt the python3 migration later. #273

This commit is contained in:
2018-11-22 13:35:19 -06:00
parent 4391e3d3de
commit 221d1d413b
53 changed files with 264 additions and 190 deletions

View File

@@ -22,9 +22,9 @@ def is_long(tweet):
""" Check if the passed tweet contains a quote in its metadata.
tweet dict: a tweet dictionary.
returns True if a quote is detected, False otherwise."""
if tweet.has_key("quoted_status_id") and tweet.has_key("quoted_status"):
if "quoted_status_id" in tweet and "quoted_status" in tweet:
return tweet["quoted_status_id"]
elif tweet.has_key("retweeted_status") and tweet["retweeted_status"].has_key("quoted_status_id") and tweet["retweeted_status"].has_key("quoted_status"):
elif "retweeted_status" in tweet and "quoted_status_id" in tweet["retweeted_status"] and "quoted_status" in tweet["retweeted_status"]:
return tweet["retweeted_status"]["quoted_status_id"]
return False
@@ -32,8 +32,8 @@ def clear_url(tweet):
""" Reads data from a quoted tweet and removes the link to the Status from the tweet's text.
tweet dict: a tweet dictionary.
returns a tweet dictionary without the URL to the status ID in its text to display."""
if tweet.has_key("retweeted_status"):
if tweet["retweeted_status"].has_key("full_text"):
if "retweeted_status" in tweet:
if "full_text" in tweet["retweeted_status"]:
value = "full_text"
else:
value = "text"
@@ -41,7 +41,7 @@ def clear_url(tweet):
try: tweet["message"] = tweet["message"].replace(urls[-1], "")
except IndexError: pass
else:
if tweet.has_key("full_text"):
if "full_text" in tweet:
value = "full_text"
else:
value = "text"

View File

@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
from __future__ import print_function
import logging
import requests
import keys
@@ -47,7 +48,7 @@ def is_long(tweet):
# see https://github.com/manuelcortez/TWBlue/issues/103
except TypeError:
pass
if long == False and tweet.has_key("retweeted_status"):
if long == False and "retweeted_status" in tweet:
for url in range(0, len(tweet["retweeted_status"]["entities"]["urls"])):
try:
if tweet["retweeted_status"]["entities"]["urls"][url] != None and "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]:
@@ -97,5 +98,5 @@ def create_tweet(user_token, user_secret, text, media=0):
try:
return response.json()["text_to_tweet"]
except:
print "There was a problem creating a long tweet"
print("There was a problem creating a long tweet")
return 0