TWBlue can now send long tweets directly to twishort. TWBlue server is nolonger used for this purpose

This commit is contained in:
Jose Manuel Delicado 2016-10-02 14:35:54 +02:00
parent a2cf1ac8d0
commit 2dd262cc83

View File

@ -18,8 +18,8 @@
############################################################ ############################################################
import requests import requests
import keys import keys
import application
from twitter import utils from twitter import utils
from requests_oauthlib import OAuth1Session
def get_twishort_uri(url): def get_twishort_uri(url):
try: try:
@ -42,13 +42,24 @@ def get_full_text(uri):
# return False # return False
def create_tweet(user_token, user_secret, text, media=0): def create_tweet(user_token, user_secret, text, media=0):
if application.snapshot == True: twitter = OAuth1Session(keys.keyring.get("api_key"), client_secret=keys.keyring.get("api_secret"), resource_owner_key=user_token, resource_owner_secret=user_secret)
url = "http://twblue.es/snapshot_twishort.php" twishort_key=keys.keyring.get("twishort_api_key")
else: x_auth_service_provider = "https://api.twitter.com/1.1/account/verify_credentials.json"
url = "http://twblue.es/stable_twishort.php" twishort_post_url = "http://api.twishort.com/1.1/post.json"
data = {"user_token": user_token, twishort_update_ids_url = "http://api.twishort.com/1.1/update_ids.json"
"user_secret": user_secret, r=requests.Request('GET', x_auth_service_provider)
prep=twitter.prepare_request(r)
resp=twitter.send(prep)
twitter.headers={
'X-Auth-Service-Provider':x_auth_service_provider,
'X-Verify-Credentials-Authorization':prep.headers['Authorization'],
}
data = {'api_key':twishort_key,
"text": text.encode("utf-8"), "text": text.encode("utf-8"),
"media": media} "media": media}
response = requests.post(url, data=data) response = twitter.post(twishort_post_url, data=data)
return response.json()["text_to_tweet"] try:
return response.json()["text_to_tweet"]
except:
print "There was a problem creating a long tweet"
return 0