twitter #2

Merged
s434708 merged 50 commits from twitter into master 2022-06-09 19:42:33 +02:00
Showing only changes of commit 2b1f3405a0 - Show all commits

View File

@ -57,13 +57,20 @@ def add_twitter_account():
core_url = 'http://65.108.80.28:4999/generate'
payload = {
"data": request_json['user_input'],
"length": 400
"length": 420
}
response = requests.post(core_url, headers={"Content-Type":"application/json"}, data=json.dumps(payload))
generated_content = response.content.decode("utf-8").replace('<|endoftext|>', '')
#generated_content = "This is wonderful post content generated by our very smart core API!"
generated_content = response.content.decode("utf-8").replace('<|endoftext|>', '').replace(' ', ' ')
trimmed_text = generated_content[:270]
dot_index = trimmed_text.rfind(".")
space_index = trimmed_text.rfind(" ")
if dot_index > 0:
tweet_text = trimmed_text[:dot_index]
else:
tweet_text = trimmed_text[:space_index]
# create post on twitter
oauth = OAuth1Session(
@ -75,7 +82,7 @@ def add_twitter_account():
response = oauth.post(
"https://api.twitter.com/2/tweets",
json={"text": generated_content[0:260]},
json={"text": tweet_text},
).json()['data']
# save campaign to database
@ -84,7 +91,7 @@ def add_twitter_account():
user_id = user_id,
twitter_account_id = request_json['twitter_account_id'],
user_input = request_json['user_input'],
generated_content = generated_content[0:260],
generated_content = tweet_text,
twitter_post_id = response['id']
)