core integration v1
This commit is contained in:
parent
ac7e7a44e0
commit
abf43f17ec
@ -22,7 +22,6 @@ def create_app():
|
|||||||
campaign_db.init_app(app)
|
campaign_db.init_app(app)
|
||||||
|
|
||||||
twitter_db.create_all(app=app)
|
twitter_db.create_all(app=app)
|
||||||
campaign_db.drop_all(app=app)
|
|
||||||
campaign_db.create_all(app=app)
|
campaign_db.create_all(app=app)
|
||||||
|
|
||||||
app.register_blueprint(twitter, url_prefix='/twitter')
|
app.register_blueprint(twitter, url_prefix='/twitter')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import requests
|
||||||
|
import json
|
||||||
from requests_oauthlib import OAuth1Session
|
from requests_oauthlib import OAuth1Session
|
||||||
from flask import Blueprint, current_app, request, jsonify
|
from flask import Blueprint, current_app, request, jsonify
|
||||||
from ayct_backend.twitter.models import *
|
from ayct_backend.twitter.models import *
|
||||||
@ -38,8 +39,17 @@ def add_twitter_account():
|
|||||||
|
|
||||||
twitter_account = TwitterAccount.query.filter_by(twitter_account_id=json['twitter_account_id']).first()
|
twitter_account = TwitterAccount.query.filter_by(twitter_account_id=json['twitter_account_id']).first()
|
||||||
|
|
||||||
# generate campaign content, change after core integration
|
# generate campaign content
|
||||||
generated_content = "This is wonderful post content generated by our very smart core API!"
|
core_url = 'http://65.108.80.28:4999/generate'
|
||||||
|
payload = {
|
||||||
|
"data": json['user_input'],
|
||||||
|
"length": 400
|
||||||
|
}
|
||||||
|
|
||||||
|
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!"
|
||||||
|
|
||||||
# create post on twitter
|
# create post on twitter
|
||||||
oauth = OAuth1Session(
|
oauth = OAuth1Session(
|
||||||
@ -51,7 +61,7 @@ def add_twitter_account():
|
|||||||
|
|
||||||
response = oauth.post(
|
response = oauth.post(
|
||||||
"https://api.twitter.com/2/tweets",
|
"https://api.twitter.com/2/tweets",
|
||||||
json={"text": generated_content},
|
json={"text": generated_content[0:260]},
|
||||||
).json()['data']
|
).json()['data']
|
||||||
|
|
||||||
# save campaign to database
|
# save campaign to database
|
||||||
|
Loading…
Reference in New Issue
Block a user